@@ -21,9 +21,6 @@ import { fromNow } from 'vs/base/common/date';
2121import { pad } from 'vs/base/common/strings' ;
2222import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer' ;
2323
24- const CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW = new RawContextKey < boolean > ( 'showUserDataSyncRemoteHistoryView' , false ) ;
25- const CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW = new RawContextKey < boolean > ( 'showUserDataSyncLocalHistoryView' , false ) ;
26-
2724export class UserDataSyncViewContribution implements IWorkbenchContribution {
2825
2926 constructor (
@@ -33,8 +30,8 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
3330 @IUserDataSyncBackupStoreService private readonly userDataSyncBackupStoreService : IUserDataSyncBackupStoreService ,
3431 ) {
3532 const container = this . registerSyncViewContainer ( ) ;
36- this . registerRemoteHistoryView ( container ) ;
37- this . registerLocalHistoryView ( container ) ;
33+ this . registerBackupView ( container , true ) ;
34+ this . registerBackupView ( container , false ) ;
3835 }
3936
4037 private registerSyncViewContainer ( ) : ViewContainer {
@@ -51,74 +48,28 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
5148 } , ViewContainerLocation . Sidebar ) ;
5249 }
5350
54- private registerRemoteHistoryView ( container : ViewContainer ) : void {
55- const id = 'workbench.views.sync.remoteHistory' ;
56- const name = localize ( 'title' , "Backup (Remote)" ) ;
57- const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW . bindTo ( this . contextKeyService ) ;
58- const treeView = this . instantiationService . createInstance ( TreeView , id , name ) ;
59- treeView . showCollapseAllAction = true ;
60- treeView . showRefreshAction = true ;
61- const disposable = treeView . onDidChangeVisibility ( visible => {
62- if ( visible && ! treeView . dataProvider ) {
63- disposable . dispose ( ) ;
64- treeView . dataProvider = this . instantiationService . createInstance ( UserDataSyncHistoryViewDataProvider , id ,
65- ( resourceKey : ResourceKey ) => this . userDataSyncStoreService . getAllRefs ( resourceKey ) , ( resourceKey : ResourceKey , ref : string ) => toRemoteSyncResource ( resourceKey , ref ) ) ;
66- }
67- } ) ;
68- const viewsRegistry = Registry . as < IViewsRegistry > ( Extensions . ViewsRegistry ) ;
69- viewsRegistry . registerViews ( [ < ITreeViewDescriptor > {
70- id,
71- name,
72- ctorDescriptor : new SyncDescriptor ( TreeViewPane ) ,
73- when : ContextKeyExpr . and ( CONTEXT_SYNC_ENABLEMENT , CONTEXT_SHOW_USER_DATA_SYNC_REMOTE_HISTORY_VIEW ) ,
74- canToggleVisibility : true ,
75- canMoveView : true ,
76- treeView,
77- collapsed : false ,
78- order : 100 ,
79- } ] , container ) ;
80-
81- registerAction2 ( class extends Action2 {
82- constructor ( ) {
83- super ( {
84- id : 'workbench.actions.showSyncRemoteHistoryView' ,
85- title : { value : localize ( 'workbench.action.showSyncRemoteHistory' , "Show Backup (Remote)" ) , original : `Show Backup (Remote)` } ,
86- category : { value : localize ( 'sync' , "Sync" ) , original : `Sync` } ,
87- menu : {
88- id : MenuId . CommandPalette ,
89- when : CONTEXT_SYNC_ENABLEMENT
90- } ,
91- } ) ;
92- }
93- async run ( accessor : ServicesAccessor ) : Promise < void > {
94- viewEnablementContext . set ( true ) ;
95- accessor . get ( IViewsService ) . openView ( id , true ) ;
96- }
97- } ) ;
98-
99- this . registerActions ( id ) ;
100- }
101-
102- private registerLocalHistoryView ( container : ViewContainer ) : void {
103- const id = 'workbench.views.sync.localHistory' ;
104- const name = localize ( 'local view title' , "Backup (Local)" ) ;
105- const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW . bindTo ( this . contextKeyService ) ;
51+ private registerBackupView ( container : ViewContainer , remote : boolean ) : void {
52+ const id = `workbench.views.sync.${ remote ? 'remote' : 'local' } BackupView` ;
53+ const name = remote ? localize ( 'remote title' , "Backup (Remote)" ) : localize ( 'local title' , "Backup (Local)" ) ;
54+ const contextKey = new RawContextKey < boolean > ( `showUserDataSync${ remote ? 'Remote' : 'Local' } BackupView` , false ) ;
55+ const viewEnablementContext = contextKey . bindTo ( this . contextKeyService ) ;
10656 const treeView = this . instantiationService . createInstance ( TreeView , id , name ) ;
10757 treeView . showCollapseAllAction = true ;
10858 treeView . showRefreshAction = true ;
10959 const disposable = treeView . onDidChangeVisibility ( visible => {
11060 if ( visible && ! treeView . dataProvider ) {
11161 disposable . dispose ( ) ;
11262 treeView . dataProvider = this . instantiationService . createInstance ( UserDataSyncHistoryViewDataProvider , id ,
113- ( resourceKey : ResourceKey ) => this . userDataSyncBackupStoreService . getAllRefs ( resourceKey ) , ( resourceKey : ResourceKey , ref : string ) => toLocalBackupSyncResource ( resourceKey , ref ) ) ;
63+ ( resourceKey : ResourceKey ) => remote ? this . userDataSyncStoreService . getAllRefs ( resourceKey ) : this . userDataSyncBackupStoreService . getAllRefs ( resourceKey ) ,
64+ ( resourceKey : ResourceKey , ref : string ) => remote ? toRemoteSyncResource ( resourceKey , ref ) : toLocalBackupSyncResource ( resourceKey , ref ) ) ;
11465 }
11566 } ) ;
11667 const viewsRegistry = Registry . as < IViewsRegistry > ( Extensions . ViewsRegistry ) ;
11768 viewsRegistry . registerViews ( [ < ITreeViewDescriptor > {
11869 id,
11970 name,
12071 ctorDescriptor : new SyncDescriptor ( TreeViewPane ) ,
121- when : ContextKeyExpr . and ( CONTEXT_SYNC_ENABLEMENT , CONTEXT_SHOW_USER_DATA_SYNC_LOCAL_HISTORY_VIEW ) ,
72+ when : ContextKeyExpr . and ( CONTEXT_SYNC_ENABLEMENT , contextKey ) ,
12273 canToggleVisibility : true ,
12374 canMoveView : true ,
12475 treeView,
@@ -129,8 +80,10 @@ export class UserDataSyncViewContribution implements IWorkbenchContribution {
12980 registerAction2 ( class extends Action2 {
13081 constructor ( ) {
13182 super ( {
132- id : 'workbench.actions.showSyncLocalHistoryView' ,
133- title : { value : localize ( 'workbench.action.showSyncLocalHistory' , "Show Backup (Local)" ) , original : `Show Backup (Local)` } ,
83+ id : `workbench.actions.showSync${ remote ? 'Remote' : 'Local' } BackupView` ,
84+ title : remote ?
85+ { value : localize ( 'workbench.action.showSyncRemoteBackup' , "Show Backup (Remote)" ) , original : `Show Backup (Remote)` }
86+ : { value : localize ( 'workbench.action.showSyncLocalBackup' , "Show Backup (Local)" ) , original : `Show Backup (Local)` } ,
13487 category : { value : localize ( 'sync' , "Sync" ) , original : `Sync` } ,
13588 menu : {
13689 id : MenuId . CommandPalette ,
0 commit comments