提交 1ebdb335 编写于 作者: S Sandeep Somavarapu

reuse code

上级 12088887
...@@ -21,9 +21,6 @@ import { fromNow } from 'vs/base/common/date'; ...@@ -21,9 +21,6 @@ import { fromNow } from 'vs/base/common/date';
import { pad } from 'vs/base/common/strings'; import { pad } from 'vs/base/common/strings';
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer'; import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
const CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW = new RawContextKey<boolean>('showUserDataSyncRemoteHistoryView', false);
const CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW = new RawContextKey<boolean>('showUserDataSyncLocalHistoryView', false);
export class UserDataSyncViewContribution implements IWorkbenchContribution { export class UserDataSyncViewContribution implements IWorkbenchContribution {
constructor( constructor(
...@@ -33,8 +30,8 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution { ...@@ -33,8 +30,8 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
@IUserDataSyncBackupStoreService private readonly userDataSyncBackupStoreService: IUserDataSyncBackupStoreService, @IUserDataSyncBackupStoreService private readonly userDataSyncBackupStoreService: IUserDataSyncBackupStoreService,
) { ) {
const container = this.registerSyncViewContainer(); const container = this.registerSyncViewContainer();
this.registerRemoteHistoryView(container); this.registerBackupView(container, true);
this.registerLocalHistoryView(container); this.registerBackupView(container, false);
} }
private registerSyncViewContainer(): ViewContainer { private registerSyncViewContainer(): ViewContainer {
...@@ -51,58 +48,11 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution { ...@@ -51,58 +48,11 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
}, ViewContainerLocation.Sidebar); }, ViewContainerLocation.Sidebar);
} }
private registerRemoteHistoryView(container: ViewContainer): void { private registerBackupView(container: ViewContainer, remote: boolean): void {
const id = 'workbench.views.sync.remoteHistory'; const id = `workbench.views.sync.${remote ? 'remote' : 'local'}BackupView`;
const name = localize('title', "Backup (Remote)"); const name = remote ? localize('remote title', "Backup (Remote)") : localize('local title', "Backup (Local)");
const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW.bindTo(this.contextKeyService); const contextKey = new RawContextKey<boolean>(`showUserDataSync${remote ? 'Remote' : 'Local'}BackupView`, false);
const treeView = this.instantiationService.createInstance(TreeView, id, name); const viewEnablementContext = contextKey.bindTo(this.contextKeyService);
treeView.showCollapseAllAction = true;
treeView.showRefreshAction = true;
const disposable = treeView.onDidChangeVisibility(visible => {
if (visible && !treeView.dataProvider) {
disposable.dispose();
treeView.dataProvider = this.instantiationService.createInstance(UserDataSyncHistoryViewDataProvider, id,
(resourceKey: ResourceKey) => this.userDataSyncStoreService.getAllRefs(resourceKey), (resourceKey: ResourceKey, ref: string) => toRemoteSyncResource(resourceKey, ref));
}
});
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
viewsRegistry.registerViews([<ITreeViewDescriptor>{
id,
name,
ctorDescriptor: new SyncDescriptor(TreeViewPane),
when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW),
canToggleVisibility: true,
canMoveView: true,
treeView,
collapsed: false,
order: 100,
}], container);
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.actions.showSyncRemoteHistoryView',
title: { value: localize('workbench.action.showSyncRemoteHistory', "Show Backup (Remote)"), original: `Show Backup (Remote)` },
category: { value: localize('sync', "Sync"), original: `Sync` },
menu: {
id: MenuId.CommandPalette,
when: CONTEXT_SYNC_ENABLEMENT
},
});
}
async run(accessor: ServicesAccessor): Promise<void> {
viewEnablementContext.set(true);
accessor.get(IViewsService).openView(id, true);
}
});
this.registerActions(id);
}
private registerLocalHistoryView(container: ViewContainer): void {
const id = 'workbench.views.sync.localHistory';
const name = localize('local view title', "Backup (Local)");
const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW.bindTo(this.contextKeyService);
const treeView = this.instantiationService.createInstance(TreeView, id, name); const treeView = this.instantiationService.createInstance(TreeView, id, name);
treeView.showCollapseAllAction = true; treeView.showCollapseAllAction = true;
treeView.showRefreshAction = true; treeView.showRefreshAction = true;
...@@ -110,7 +60,8 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution { ...@@ -110,7 +60,8 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
if (visible && !treeView.dataProvider) { if (visible && !treeView.dataProvider) {
disposable.dispose(); disposable.dispose();
treeView.dataProvider = this.instantiationService.createInstance(UserDataSyncHistoryViewDataProvider, id, treeView.dataProvider = this.instantiationService.createInstance(UserDataSyncHistoryViewDataProvider, id,
(resourceKey: ResourceKey) => this.userDataSyncBackupStoreService.getAllRefs(resourceKey), (resourceKey: ResourceKey, ref: string) => toLocalBackupSyncResource(resourceKey, ref)); (resourceKey: ResourceKey) => remote ? this.userDataSyncStoreService.getAllRefs(resourceKey) : this.userDataSyncBackupStoreService.getAllRefs(resourceKey),
(resourceKey: ResourceKey, ref: string) => remote ? toRemoteSyncResource(resourceKey, ref) : toLocalBackupSyncResource(resourceKey, ref));
} }
}); });
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry); const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
...@@ -118,7 +69,7 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution { ...@@ -118,7 +69,7 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
id, id,
name, name,
ctorDescriptor: new SyncDescriptor(TreeViewPane), ctorDescriptor: new SyncDescriptor(TreeViewPane),
when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW), when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, contextKey),
canToggleVisibility: true, canToggleVisibility: true,
canMoveView: true, canMoveView: true,
treeView, treeView,
...@@ -129,8 +80,10 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution { ...@@ -129,8 +80,10 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
registerAction2(class extends Action2 { registerAction2(class extends Action2 {
constructor() { constructor() {
super({ super({
id: 'workbench.actions.showSyncLocalHistoryView', id: `workbench.actions.showSync${remote ? 'Remote' : 'Local'}BackupView`,
title: { value: localize('workbench.action.showSyncLocalHistory', "Show Backup (Local)"), original: `Show Backup (Local)` }, title: remote ?
{ value: localize('workbench.action.showSyncRemoteBackup', "Show Backup (Remote)"), original: `Show Backup (Remote)` }
: { value: localize('workbench.action.showSyncLocalBackup', "Show Backup (Local)"), original: `Show Backup (Local)` },
category: { value: localize('sync', "Sync"), original: `Sync` }, category: { value: localize('sync', "Sync"), original: `Sync` },
menu: { menu: {
id: MenuId.CommandPalette, id: MenuId.CommandPalette,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册