Skip to content

Commit

Permalink
#96370 show sync views when signed in
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed May 7, 2020
1 parent d487078 commit 5806a91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const syncNowCommand = {
const showSyncSettingsCommand = { id: 'workbench.userData.actions.syncSettings', title: localize('sync settings', "Preferences Sync: Show Settings"), };

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

export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {

Expand Down
34 changes: 19 additions & 15 deletions src/vs/workbench/contrib/userDataSync/browser/userDataSyncView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,35 @@ import { localize } from 'vs/nls';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { TreeViewPane, TreeView } from 'vs/workbench/browser/parts/views/treeView';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ALL_SYNC_RESOURCES, CONTEXT_SYNC_ENABLEMENT, SyncResource, IUserDataSyncService, ISyncResourceHandle } from 'vs/platform/userDataSync/common/userDataSync';
import { ALL_SYNC_RESOURCES, SyncResource, IUserDataSyncService, ISyncResourceHandle, CONTEXT_SYNC_STATE, SyncStatus } from 'vs/platform/userDataSync/common/userDataSync';
import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService, RawContextKey, ContextKeyExpr, ContextKeyEqualsExpr } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, RawContextKey, ContextKeyExpr, ContextKeyEqualsExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { FolderThemeIcon } from 'vs/platform/theme/common/themeService';
import { fromNow } from 'vs/base/common/date';
import { pad, uppercaseFirstLetter } from 'vs/base/common/strings';
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
import { Codicon } from 'vs/base/common/codicons';
import { CONTEXT_ACCOUNT_STATE } from 'vs/workbench/contrib/userDataSync/browser/userDataSync';
import { AccountStatus } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncAccount';

export const VIEW_CONTAINER_ID = 'workbench.view.sync';
const CONTEXT_ENABLE_VIEWS = new RawContextKey<boolean>(`showUserDataSyncViews`, false);

export class UserDataSyncViewContribution implements IWorkbenchContribution {

private readonly viewsEnablementContext: IContextKey<boolean>;

constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
) {
const container = this.registerSyncViewContainer();
this.registerBackupView(container, true);
this.registerBackupView(container, false);
this.viewsEnablementContext = CONTEXT_ENABLE_VIEWS.bindTo(this.contextKeyService);
this.registerView(container, true);
this.registerView(container, false);
}

private registerSyncViewContainer(): ViewContainer {
Expand All @@ -49,11 +55,10 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
}, ViewContainerLocation.Sidebar);
}

private registerBackupView(container: ViewContainer, remote: boolean): void {
const id = `workbench.views.sync.${remote ? 'remote' : 'local'}BackupView`;
const name = remote ? localize('remote title', "Remote Backup") : localize('local title', "Local Backup");
const contextKey = new RawContextKey<boolean>(`showUserDataSync${remote ? 'Remote' : 'Local'}BackupView`, false);
const viewEnablementContext = contextKey.bindTo(this.contextKeyService);
private registerView(container: ViewContainer, remote: boolean): void {
const that = this;
const id = `workbench.views.sync.${remote ? 'remote' : 'local'}DataView`;
const name = remote ? localize('remote title', "Remote Data") : localize('local title', "Local Backup");
const treeView = this.instantiationService.createInstance(TreeView, id, name);
treeView.showCollapseAllAction = true;
treeView.showRefreshAction = true;
Expand All @@ -68,7 +73,7 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
id,
name,
ctorDescriptor: new SyncDescriptor(TreeViewPane),
when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, contextKey),
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), CONTEXT_ACCOUNT_STATE.isEqualTo(AccountStatus.Available), CONTEXT_ENABLE_VIEWS),
canToggleVisibility: true,
canMoveView: true,
treeView,
Expand All @@ -79,21 +84,21 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
registerAction2(class extends Action2 {
constructor() {
super({
id: `workbench.actions.showSync${remote ? 'Remote' : 'Local'}BackupView`,
id: `workbench.actions.showSync${remote ? 'Remote' : 'Local'}DataView`,
title: remote ?
{ value: localize('workbench.action.showSyncRemoteBackup', "Show Remote Backup"), original: `Show Remote Backup` }
{ value: localize('workbench.action.showSyncRemoteBackup', "Show Remote Data"), original: `Show Remote Data` }
: { value: localize('workbench.action.showSyncLocalBackup', "Show Local Backup"), original: `Show Local Backup` },
category: { value: localize('sync preferences', "Preferences Sync"), original: `Preferences Sync` },
menu: {
id: MenuId.CommandPalette,
when: CONTEXT_SYNC_ENABLEMENT
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), CONTEXT_ACCOUNT_STATE.isEqualTo(AccountStatus.Available)),
},
});
}
async run(accessor: ServicesAccessor): Promise<void> {
const viewDescriptorService = accessor.get(IViewDescriptorService);
const viewsService = accessor.get(IViewsService);
viewEnablementContext.set(true);
that.viewsEnablementContext.set(true);
const viewContainer = viewDescriptorService.getViewContainerByViewId(id);
if (viewContainer) {
const model = viewDescriptorService.getViewContainerModel(viewContainer);
Expand All @@ -107,7 +112,6 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
}
});
}

}
}
});
Expand Down

0 comments on commit 5806a91

Please sign in to comment.