Skip to content

Commit

Permalink
#93960 Show configure and log actions in sync views
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed May 12, 2020
1 parent 6eec8bd commit eab3ebf
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 256 deletions.
6 changes: 6 additions & 0 deletions src/vs/platform/userDataSync/common/userDataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,9 @@ export function getSyncAreaLabel(source: SyncResource): string {
case SyncResource.GlobalState: return localize('ui state label', "UI State");
}
}

// Commands
export const TURN_ON_SYNC_COMMAND_ID = 'workbench.userDataSync.actions.turnOn';
export const TURN_OFF_SYNC_COMMAND_ID = 'workbench.userDataSync.actions.turnOff';
export const MANAGE_SYNC_COMMAND_ID = 'workbench.userDataSync.actions.configure';
export const SHOW_SYNC_LOG_COMMAND_ID = 'workbench.userDataSync.actions.showLog';
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } fr
import { Registry } from 'vs/platform/registry/common/platform';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { UserDataSyncWorkbenchContribution } from 'vs/workbench/contrib/userDataSync/browser/userDataSync';
import { UserDataSyncViewContribution } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncView';
import { UserDataSyncDataViewsContribution } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncDataViews';

const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(UserDataSyncWorkbenchContribution, LifecyclePhase.Ready);
workbenchRegistry.registerWorkbenchContribution(UserDataSyncViewContribution, LifecyclePhase.Ready);
workbenchRegistry.registerWorkbenchContribution(UserDataSyncDataViewsContribution, LifecyclePhase.Ready);
53 changes: 40 additions & 13 deletions src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import {
CONTEXT_SYNC_STATE, IUserDataAutoSyncService, IUserDataSyncService, registerConfiguration,
SyncResource, SyncStatus, UserDataSyncError, UserDataSyncErrorCode, USER_DATA_SYNC_SCHEME, IUserDataSyncEnablementService, CONTEXT_SYNC_ENABLEMENT,
SyncResourceConflicts, Conflict, getSyncResourceFromLocalPreview, getSyncAreaLabel
SyncResourceConflicts, Conflict, getSyncResourceFromLocalPreview, getSyncAreaLabel, SHOW_SYNC_LOG_COMMAND_ID, MANAGE_SYNC_COMMAND_ID, TURN_OFF_SYNC_COMMAND_ID, TURN_ON_SYNC_COMMAND_ID
} from 'vs/platform/userDataSync/common/userDataSync';
import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWidgets';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
Expand All @@ -49,6 +49,11 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { UserDataSyncAccounts, AccountStatus } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncAccount';
import { Registry } from 'vs/platform/registry/common/platform';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { Codicon } from 'vs/base/common/codicons';
import { ViewContainerLocation, IViewContainersRegistry, Extensions } from 'vs/workbench/common/views';
import { UserDataSyncViewPaneContainer } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncView';

const CONTEXT_CONFLICTS_SOURCES = new RawContextKey<string>('conflictsSources', '');

Expand All @@ -63,15 +68,17 @@ type FirstTimeSyncClassification = {
action: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
};

const turnOnSyncCommand = { id: 'workbench.userData.actions.syncStart', title: localize('turn on sync with category', "Preferences Sync: Turn On...") };
const stopSyncCommand = { id: 'workbench.userData.actions.stopSync', title: localize('stop sync', "Preferences Sync: Turn Off") };
const resolveSettingsConflictsCommand = { id: 'workbench.userData.actions.resolveSettingsConflicts', title: localize('showConflicts', "Preferences Sync: Show Settings Conflicts") };
const resolveKeybindingsConflictsCommand = { id: 'workbench.userData.actions.resolveKeybindingsConflicts', title: localize('showKeybindingsConflicts', "Preferences Sync: Show Keybindings Conflicts") };
const resolveSnippetsConflictsCommand = { id: 'workbench.userData.actions.resolveSnippetsConflicts', title: localize('showSnippetsConflicts', "Preferences Sync: Show User Snippets Conflicts") };
const configureSyncCommand = { id: 'workbench.userData.actions.configureSync', title: localize('configure sync', "Preferences Sync: Configure...") };
const showSyncActivityCommand = { id: 'workbench.userData.actions.showSyncActivity', title: localize('show sync log title', "Preferences Sync: Show Log") };
export const VIEW_CONTAINER_ID = 'workbench.view.sync';

const turnOnSyncCommand = { id: TURN_ON_SYNC_COMMAND_ID, title: localize('turn on sync with category', "Preferences Sync: Turn On...") };
const turnOffSyncCommand = { id: TURN_OFF_SYNC_COMMAND_ID, title: localize('stop sync', "Preferences Sync: Turn Off") };
const configureSyncCommand = { id: MANAGE_SYNC_COMMAND_ID, title: localize('configure sync', "Preferences Sync: Configure...") };
const showSyncActivityCommand = { id: SHOW_SYNC_LOG_COMMAND_ID, title: localize('show sync log title', "Preferences Sync: Show Log") };
const resolveSettingsConflictsCommand = { id: 'workbench.userDataSync.actions.resolveSettingsConflicts', title: localize('showConflicts', "Preferences Sync: Show Settings Conflicts") };
const resolveKeybindingsConflictsCommand = { id: 'workbench.userDataSync.actions.resolveKeybindingsConflicts', title: localize('showKeybindingsConflicts', "Preferences Sync: Show Keybindings Conflicts") };
const resolveSnippetsConflictsCommand = { id: 'workbench.userDataSync.actions.resolveSnippetsConflicts', title: localize('showSnippetsConflicts', "Preferences Sync: Show User Snippets Conflicts") };
const syncNowCommand = {
id: 'workbench.userData.actions.syncNow',
id: 'workbench.userDataSync.actions.syncNow',
title: localize('sync now', "Preferences Sync: Sync Now"),
description(userDataSyncService: IUserDataSyncService): string | undefined {
if (userDataSyncService.status === SyncStatus.Syncing) {
Expand All @@ -83,10 +90,11 @@ const syncNowCommand = {
return undefined;
}
};
const showSyncSettingsCommand = { id: 'workbench.userData.actions.syncSettings', title: localize('sync settings', "Preferences Sync: Show Settings"), };
const showSyncSettingsCommand = { id: 'workbench.userDataSync.actions.settings', title: localize('sync settings', "Preferences Sync: Show Settings"), };

const CONTEXT_TURNING_ON_STATE = new RawContextKey<false>('userDataSyncTurningOn', false);
export const CONTEXT_ACCOUNT_STATE = new RawContextKey<string>('userDataSyncAccountStatus', AccountStatus.Uninitialized);
export const CONTEXT_ENABLE_VIEWS = new RawContextKey<boolean>(`showUserDataSyncViews`, false);

export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {

Expand Down Expand Up @@ -147,6 +155,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
this._register(this.userDataSyncAccounts.onDidChangeStatus(status => this.onDidChangeAccountStatus(status)));
this._register(this.userDataSyncAccounts.onDidSignOut(() => this.doTurnOff(false)));
this.registerActions();
this.registerViewContainer();

textModelResolverService.registerTextModelContentProvider(USER_DATA_SYNC_SCHEME, instantiationService.createInstance(UserDataRemoteContentProvider));
registerEditorContribution(AcceptChangesContribution.ID, AcceptChangesContribution);
Expand Down Expand Up @@ -937,7 +946,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
items.push({ id: syncNowCommand.id, label: syncNowCommand.title, description: syncNowCommand.description(that.userDataSyncService) });
if (that.userDataSyncEnablementService.canToggleEnablement()) {
const account = that.userDataSyncAccounts.current;
items.push({ id: stopSyncCommand.id, label: stopSyncCommand.title, description: account ? `${account.accountName} (${that.authenticationService.getDisplayName(account.authenticationProviderId)})` : undefined });
items.push({ id: turnOffSyncCommand.id, label: turnOffSyncCommand.title, description: account ? `${account.accountName} (${that.authenticationService.getDisplayName(account.authenticationProviderId)})` : undefined });
}
quickPick.items = items;
disposables.add(quickPick.onDidAccept(() => {
Expand All @@ -963,6 +972,10 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
super({
id: syncNowCommand.id,
title: syncNowCommand.title,
menu: {
id: MenuId.CommandPalette,
when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_ACCOUNT_STATE.isEqualTo(AccountStatus.Available), CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized))
}
});
}
run(): Promise<any> {
Expand All @@ -976,8 +989,8 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
this._register(registerAction2(class StopSyncAction extends Action2 {
constructor() {
super({
id: stopSyncCommand.id,
title: stopSyncCommand.title,
id: turnOffSyncCommand.id,
title: turnOffSyncCommand.title,
menu: {
id: MenuId.CommandPalette,
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), CONTEXT_SYNC_ENABLEMENT),
Expand Down Expand Up @@ -1048,6 +1061,20 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}));
}

private registerViewContainer(): void {
Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer(
{
id: VIEW_CONTAINER_ID,
name: localize('sync preferences', "Preferences Sync"),
ctorDescriptor: new SyncDescriptor(
UserDataSyncViewPaneContainer,
[VIEW_CONTAINER_ID, this.userDataSyncAccounts]
),
icon: Codicon.sync.classNames,
hideIfEmpty: true,
}, ViewContainerLocation.Sidebar);
}

}

class UserDataRemoteContentProvider implements ITextModelContentProvider {
Expand Down
Loading

0 comments on commit eab3ebf

Please sign in to comment.