|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 |
| -import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; |
7 |
| -import { IUserDataSyncService, SyncStatus, SyncSource, CONTEXT_SYNC_STATE, IUserDataSyncStore, registerConfiguration, getUserDataSyncStore, ISyncConfiguration, IUserDataAuthTokenService, IUserDataAutoSyncService, USER_DATA_SYNC_SCHEME, toRemoteContentResource, getSyncSourceFromRemoteContentResource, UserDataSyncErrorCode, UserDataSyncError, getSyncSourceFromPreviewResource, IUserDataSyncEnablementService, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync'; |
8 |
| -import { localize } from 'vs/nls'; |
9 |
| -import { Disposable, MutableDisposable, toDisposable, DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle'; |
10 |
| -import { CommandsRegistry } from 'vs/platform/commands/common/commands'; |
11 |
| -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
12 |
| -import { MenuRegistry, MenuId, IMenuItem } from 'vs/platform/actions/common/actions'; |
13 |
| -import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey, ContextKeyRegexExpr } from 'vs/platform/contextkey/common/contextkey'; |
14 |
| -import { IActivityService, IBadge, NumberBadge, ProgressBadge } from 'vs/workbench/services/activity/common/activity'; |
15 |
| -import { GLOBAL_ACTIVITY_ID } from 'vs/workbench/common/activity'; |
16 |
| -import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; |
17 |
| -import { URI } from 'vs/base/common/uri'; |
18 |
| -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; |
| 6 | +import { Action } from 'vs/base/common/actions'; |
| 7 | +import { timeout } from 'vs/base/common/async'; |
| 8 | +import { toErrorMessage } from 'vs/base/common/errorMessage'; |
| 9 | +import { canceled, isPromiseCanceledError } from 'vs/base/common/errors'; |
19 | 10 | import { Event } from 'vs/base/common/event';
|
20 |
| -import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; |
21 |
| -import { isEqual } from 'vs/base/common/resources'; |
22 |
| -import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; |
23 |
| -import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; |
| 11 | +import { Disposable, DisposableStore, dispose, MutableDisposable, toDisposable, IDisposable } from 'vs/base/common/lifecycle'; |
24 | 12 | import { isWeb } from 'vs/base/common/platform';
|
25 |
| -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; |
26 |
| -import { UserDataSyncTrigger } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncTrigger'; |
27 |
| -import { timeout } from 'vs/base/common/async'; |
28 |
| -import { IOutputService } from 'vs/workbench/contrib/output/common/output'; |
29 |
| -import * as Constants from 'vs/workbench/contrib/logs/common/logConstants'; |
30 |
| -import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService'; |
| 13 | +import { isEqual } from 'vs/base/common/resources'; |
| 14 | +import { URI } from 'vs/base/common/uri'; |
| 15 | +import type { ICodeEditor } from 'vs/editor/browser/editorBrowser'; |
| 16 | +import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; |
| 17 | +import type { IEditorContribution } from 'vs/editor/common/editorCommon'; |
| 18 | +import type { ITextModel } from 'vs/editor/common/model'; |
31 | 19 | import { AuthenticationSession } from 'vs/editor/common/modes';
|
32 |
| -import { isPromiseCanceledError, canceled } from 'vs/base/common/errors'; |
33 |
| -import { toErrorMessage } from 'vs/base/common/errorMessage'; |
34 |
| -import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; |
35 |
| -import { ITextModelService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService'; |
36 | 20 | import { IModelService } from 'vs/editor/common/services/modelService';
|
37 | 21 | import { IModeService } from 'vs/editor/common/services/modeService';
|
38 |
| -import type { ITextModel } from 'vs/editor/common/model'; |
39 |
| -import type { IEditorContribution } from 'vs/editor/common/editorCommon'; |
40 |
| -import type { ICodeEditor } from 'vs/editor/browser/editorBrowser'; |
| 22 | +import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService'; |
| 23 | +import { localize } from 'vs/nls'; |
| 24 | +import { IMenuItem, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions'; |
| 25 | +import { CommandsRegistry } from 'vs/platform/commands/common/commands'; |
| 26 | +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
| 27 | +import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey, ContextKeyRegexExpr } from 'vs/platform/contextkey/common/contextkey'; |
| 28 | +import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; |
| 29 | +import { IFileService } from 'vs/platform/files/common/files'; |
| 30 | +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; |
| 31 | +import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; |
| 32 | +import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; |
| 33 | +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; |
| 34 | +import { CONTEXT_SYNC_STATE, getSyncSourceFromRemoteContentResource, getUserDataSyncStore, ISyncConfiguration, IUserDataAuthTokenService, IUserDataAutoSyncService, IUserDataSyncService, IUserDataSyncStore, registerConfiguration, SyncSource, SyncStatus, toRemoteContentResource, UserDataSyncError, UserDataSyncErrorCode, USER_DATA_SYNC_SCHEME, IUserDataSyncEnablementService, ResourceKey, getSyncSourceFromPreviewResource } from 'vs/platform/userDataSync/common/userDataSync'; |
41 | 35 | import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWidgets';
|
42 |
| -import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; |
| 36 | +import { GLOBAL_ACTIVITY_ID } from 'vs/workbench/common/activity'; |
| 37 | +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; |
43 | 38 | import type { IEditorInput } from 'vs/workbench/common/editor';
|
44 |
| -import { Action } from 'vs/base/common/actions'; |
| 39 | +import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; |
| 40 | +import * as Constants from 'vs/workbench/contrib/logs/common/logConstants'; |
| 41 | +import { IOutputService } from 'vs/workbench/contrib/output/common/output'; |
| 42 | +import { UserDataSyncTrigger } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncTrigger'; |
| 43 | +import { IActivityService, IBadge, NumberBadge, ProgressBadge } from 'vs/workbench/services/activity/common/activity'; |
| 44 | +import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService'; |
| 45 | +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; |
| 46 | +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; |
45 | 47 | import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
|
46 |
| -import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; |
47 | 48 |
|
48 | 49 | const enum AuthStatus {
|
49 | 50 | Initializing = 'Initializing',
|
@@ -101,6 +102,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
101 | 102 | @ITextModelService textModelResolverService: ITextModelService,
|
102 | 103 | @IPreferencesService private readonly preferencesService: IPreferencesService,
|
103 | 104 | @ITelemetryService private readonly telemetryService: ITelemetryService,
|
| 105 | + @IFileService private readonly fileService: IFileService, |
104 | 106 | ) {
|
105 | 107 | super();
|
106 | 108 | this.userDataSyncStore = getUserDataSyncStore(configurationService);
|
@@ -256,6 +258,14 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
256 | 258 | const conflictsArea = getSyncAreaLabel(conflictsSource);
|
257 | 259 | const handle = this.notificationService.prompt(Severity.Warning, localize('conflicts detected', "Unable to sync due to conflicts in {0}. Please resolve them to continue.", conflictsArea),
|
258 | 260 | [
|
| 261 | + { |
| 262 | + label: localize('accept remote', "Accept Remote"), |
| 263 | + run: () => this.acceptConflicts('remote', conflictsSource) |
| 264 | + }, |
| 265 | + { |
| 266 | + label: localize('accept local', "Accept Local"), |
| 267 | + run: () => this.acceptConflicts('local', conflictsSource) |
| 268 | + }, |
259 | 269 | {
|
260 | 270 | label: localize('show conflicts', "Show Conflicts"),
|
261 | 271 | run: () => {
|
@@ -543,6 +553,39 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
543 | 553 | });
|
544 | 554 | }
|
545 | 555 |
|
| 556 | + private async acceptConflicts(resolutionSource: 'local' | 'remote', syncSource: SyncSource) { |
| 557 | + return syncSource === SyncSource.Settings ? this.acceptSettingConflicts(resolutionSource) : |
| 558 | + syncSource === SyncSource.Keybindings ? this.acceptKeybindingConflicts(resolutionSource) : undefined; |
| 559 | + } |
| 560 | + |
| 561 | + private async acceptSettingConflicts(resolutionSource: 'local' | 'remote'): Promise<void> { |
| 562 | + let contents: string | undefined; |
| 563 | + if (resolutionSource === 'local') { |
| 564 | + const fileContent = await this.fileService.readFile(this.workbenchEnvironmentService.settingsResource); |
| 565 | + contents = fileContent.value.toString(); |
| 566 | + } else { |
| 567 | + contents = await this.userDataSyncService.getRemoteContent(SyncSource.Settings, false) || undefined; |
| 568 | + } |
| 569 | + |
| 570 | + if (contents) { |
| 571 | + this.userDataSyncService.accept(SyncSource.Settings, contents); |
| 572 | + } |
| 573 | + } |
| 574 | + |
| 575 | + private async acceptKeybindingConflicts(resolutionSource: 'local' | 'remote'): Promise<void> { |
| 576 | + let contents: string | undefined; |
| 577 | + if (resolutionSource === 'local') { |
| 578 | + const fileContent = await this.fileService.readFile(this.workbenchEnvironmentService.keybindingsResource); |
| 579 | + contents = fileContent.value.toString(); |
| 580 | + } else { |
| 581 | + contents = await this.userDataSyncService.getRemoteContent(SyncSource.Keybindings, false) || undefined; |
| 582 | + } |
| 583 | + |
| 584 | + if (contents) { |
| 585 | + this.userDataSyncService.accept(SyncSource.Keybindings, contents); |
| 586 | + } |
| 587 | + } |
| 588 | + |
546 | 589 | private async handleConflicts(source: SyncSource): Promise<void> {
|
547 | 590 | let previewResource: URI | undefined = undefined;
|
548 | 591 | let label: string = '';
|
|
0 commit comments