@@ -49,7 +49,7 @@ import { EXPLORER_CONTAINER_ID } from '@opensumi/ide-explorer/lib/browser/explor
4949import { IMainLayoutService , IViewsRegistry , MainLayoutContribution } from '@opensumi/ide-main-layout' ;
5050import { ViewContentGroups } from '@opensumi/ide-main-layout/lib/browser/views-registry' ;
5151import { IOpenDialogOptions , ISaveDialogOptions , IWindowDialogService } from '@opensumi/ide-overlay' ;
52- import { DEFAULT_WORKSPACE_SUFFIX_NAME , IWorkspaceService , UNTITLED_WORKSPACE } from '@opensumi/ide-workspace' ;
52+ import { IWorkspaceService , UNTITLED_WORKSPACE } from '@opensumi/ide-workspace' ;
5353
5454import { IFileTreeService , PasteTypes , RESOURCE_VIEW_ID } from '../common' ;
5555import { Directory } from '../common/file-tree-node.define' ;
@@ -129,10 +129,6 @@ export class FileTreeContribution
129129 private deleteThrottler : Throttler = new Throttler ( ) ;
130130 private willDeleteUris : URI [ ] = [ ] ;
131131
132- get workspaceSuffixName ( ) {
133- return this . appConfig . workspaceSuffixName || DEFAULT_WORKSPACE_SUFFIX_NAME ;
134- }
135-
136132 initialize ( ) {
137133 // 等待排除配置初始化结束后再初始化文件树
138134 this . workspaceService . initFileServiceExclude ( ) . then ( async ( ) => {
@@ -198,7 +194,7 @@ export class FileTreeContribution
198194 if ( workspace ) {
199195 const uri = new URI ( workspace . uri ) ;
200196 resourceTitle = uri . displayName ;
201- if ( ! workspace . isDirectory && resourceTitle . endsWith ( `.${ this . workspaceSuffixName } ` ) ) {
197+ if ( ! workspace . isDirectory && resourceTitle . endsWith ( `.${ this . workspaceService . workspaceSuffixName } ` ) ) {
202198 resourceTitle = resourceTitle . slice ( 0 , resourceTitle . lastIndexOf ( '.' ) ) ;
203199 if ( resourceTitle === UNTITLED_WORKSPACE ) {
204200 return localize ( 'file.workspace.defaultTip' ) ;
@@ -246,6 +242,25 @@ export class FileTreeContribution
246242 group : '0_new' ,
247243 } ) ;
248244
245+ menuRegistry . registerMenuItem ( MenuId . ExplorerContext , {
246+ command : {
247+ id : WORKSPACE_COMMANDS . ADD_WORKSPACE_FOLDER . id ,
248+ label : localize ( 'workspace.addFolderToWorkspace' ) ,
249+ } ,
250+ order : 1 ,
251+ group : '0_workspace' ,
252+ when : 'config.workspace.supportMultiRootWorkspace' ,
253+ } ) ;
254+ menuRegistry . registerMenuItem ( MenuId . ExplorerContext , {
255+ command : {
256+ id : WORKSPACE_COMMANDS . REMOVE_WORKSPACE_FOLDER . id ,
257+ label : localize ( 'workspace.removeFolderFromWorkspace' ) ,
258+ } ,
259+ order : 1 ,
260+ group : '0_workspace' ,
261+ when : 'config.workspace.supportMultiRootWorkspace' ,
262+ } ) ;
263+
249264 menuRegistry . registerMenuItem ( MenuId . ExplorerContext , {
250265 command : {
251266 id : FILE_COMMANDS . OPEN_RESOURCES . id ,
@@ -872,29 +887,33 @@ export class FileTreeContribution
872887 this . appConfig . isElectronRenderer ,
873888 } ) ;
874889
875- if ( this . appConfig . isElectronRenderer ) {
876- commands . registerCommand ( FILE_COMMANDS . VSCODE_OPEN_FOLDER , {
877- execute : ( uri ?: URI , arg ?: boolean | { forceNewWindow ?: boolean } ) => {
878- const windowService : IWindowService = this . injector . get ( IWindowService ) ;
879- const options = { newWindow : true } ;
880- if ( typeof arg === 'boolean' ) {
881- options . newWindow = arg ;
882- } else {
883- options . newWindow = typeof arg ?. forceNewWindow === 'boolean' ? arg . forceNewWindow : true ;
884- }
890+ commands . registerCommand ( FILE_COMMANDS . VSCODE_OPEN_FOLDER , {
891+ execute : ( uri ?: URI , arg ?: boolean | { forceNewWindow ?: boolean } ) => {
892+ const windowService : IWindowService = this . injector . get ( IWindowService ) ;
893+ const options = { newWindow : true } ;
894+ if ( typeof arg === 'boolean' ) {
895+ options . newWindow = arg ;
896+ } else {
897+ options . newWindow = typeof arg ?. forceNewWindow === 'boolean' ? arg . forceNewWindow : true ;
898+ }
885899
886- if ( uri ) {
887- return windowService . openWorkspace ( uri , options ) ;
888- }
900+ if ( uri ) {
901+ return windowService . openWorkspace ( uri , options ) ;
902+ }
889903
890- return this . commandService . executeCommand ( FILE_COMMANDS . OPEN_FOLDER . id , options ) ;
891- } ,
892- } ) ;
904+ return this . commandService . executeCommand ( FILE_COMMANDS . OPEN_FOLDER . id , options ) ;
905+ } ,
906+ isVisible : ( ) => {
907+ const supportsOpenWorkspace = this . preferenceService . get < boolean > ( 'application.supportsOpenFolder' ) ;
908+ return supportsOpenWorkspace ?? false ;
909+ } ,
910+ } ) ;
893911
894- commands . registerCommand ( FILE_COMMANDS . OPEN_FOLDER , {
895- execute : ( options : { newWindow : boolean } ) => {
912+ commands . registerCommand ( FILE_COMMANDS . OPEN_FOLDER , {
913+ execute : ( options : { newWindow : boolean } ) => {
914+ const windowService : IWindowService = this . injector . get ( IWindowService ) ;
915+ if ( this . appConfig . isElectronRenderer ) {
896916 const dialogService : IElectronNativeDialogService = this . injector . get ( IElectronNativeDialogService ) ;
897- const windowService : IWindowService = this . injector . get ( IWindowService ) ;
898917 dialogService
899918 . showOpenDialog ( {
900919 title : localize ( 'workspace.openDirectory' ) ,
@@ -905,25 +924,44 @@ export class FileTreeContribution
905924 windowService . openWorkspace ( URI . file ( paths [ 0 ] ) , options || { newWindow : true } ) ;
906925 }
907926 } ) ;
908- } ,
909- } ) ;
927+ } else {
928+ const dialogService : IWindowDialogService = this . injector . get ( IWindowDialogService ) ;
929+ dialogService
930+ . showOpenDialog ( {
931+ title : localize ( 'workspace.openDirectory' ) ,
932+ canSelectFiles : false ,
933+ canSelectFolders : true ,
934+ } )
935+ . then ( ( uris ) => {
936+ if ( uris && uris . length > 0 ) {
937+ windowService . openWorkspace ( uris [ 0 ] , options || { newWindow : true } ) ;
938+ }
939+ } ) ;
940+ }
941+ } ,
942+ isVisible : ( ) => {
943+ const supportsOpenWorkspace = this . preferenceService . get < boolean > ( 'application.supportsOpenFolder' ) ;
944+ return supportsOpenWorkspace ?? false ;
945+ } ,
946+ } ) ;
910947
911- commands . registerCommand ( FILE_COMMANDS . OPEN_WORKSPACE , {
912- execute : ( options : { newWindow : boolean } ) => {
913- const supportsOpenWorkspace = this . preferenceService . get ( 'application.supportsOpenWorkspace' ) ;
914- if ( ! supportsOpenWorkspace ) {
915- return ;
916- }
948+ commands . registerCommand ( FILE_COMMANDS . OPEN_WORKSPACE , {
949+ execute : ( options ?: { newWindow : boolean } ) => {
950+ const supportsOpenWorkspace = this . preferenceService . get ( 'application.supportsOpenWorkspace' ) ;
951+ if ( ! supportsOpenWorkspace ) {
952+ return ;
953+ }
954+ const windowService : IWindowService = this . injector . get ( IWindowService ) ;
955+ if ( this . appConfig . isElectronRenderer ) {
917956 const dialogService : IElectronNativeDialogService = this . injector . get ( IElectronNativeDialogService ) ;
918- const windowService : IWindowService = this . injector . get ( IWindowService ) ;
919957 dialogService
920958 . showOpenDialog ( {
921959 title : localize ( 'workspace.openWorkspace' ) ,
922960 properties : [ 'openFile' ] ,
923961 filters : [
924962 {
925963 name : localize ( 'workspace.openWorkspaceTitle' ) ,
926- extensions : [ this . workspaceSuffixName ] ,
964+ extensions : [ this . workspaceService . workspaceSuffixName ] ,
927965 } ,
928966 ] ,
929967 } )
@@ -932,9 +970,31 @@ export class FileTreeContribution
932970 windowService . openWorkspace ( URI . file ( paths [ 0 ] ) , options || { newWindow : true } ) ;
933971 }
934972 } ) ;
935- } ,
936- } ) ;
937- }
973+ } else {
974+ const dialogService : IWindowDialogService = this . injector . get ( IWindowDialogService ) ;
975+ dialogService
976+ . showOpenDialog ( {
977+ title : localize ( 'workspace.openWorkspace' ) ,
978+ canSelectFiles : true ,
979+ canSelectFolders : false ,
980+ canSelectMany : false ,
981+ filters : {
982+ workspace : [ this . workspaceService . workspaceSuffixName ] ,
983+ } ,
984+ } )
985+ . then ( ( uris ) => {
986+ if ( uris && uris . length > 0 ) {
987+ const workspaceService : IWorkspaceService = this . injector . get ( IWorkspaceService ) ;
988+ workspaceService . open ( uris [ 0 ] , { preserveWindow : options ?. newWindow ?? false } ) ;
989+ }
990+ } ) ;
991+ }
992+ } ,
993+ isVisible : ( ) => {
994+ const supportsOpenWorkspace = this . preferenceService . get < boolean > ( 'application.supportsOpenWorkspace' ) ;
995+ return supportsOpenWorkspace ?? false ;
996+ } ,
997+ } ) ;
938998
939999 commands . registerCommand ( FILE_COMMANDS . REVEAL_IN_EXPLORER , {
9401000 execute : ( uriOrResource ?: URI | { uri ?: URI } ) => {
@@ -1178,6 +1238,15 @@ export class FileTreeContribution
11781238 viewId : RESOURCE_VIEW_ID ,
11791239 order : 5 ,
11801240 } ) ;
1241+ registry . registerItem ( {
1242+ id : WORKSPACE_COMMANDS . ADD_WORKSPACE_FOLDER . id ,
1243+ command : WORKSPACE_COMMANDS . ADD_WORKSPACE_FOLDER . id ,
1244+ label : localize ( 'workspace.addFolderToWorkspace' ) ,
1245+ viewId : RESOURCE_VIEW_ID ,
1246+ order : 0 ,
1247+ group : 'file_explore_workspace' ,
1248+ when : 'config.workspace.supportMultiRootWorkspace' ,
1249+ } ) ;
11811250 }
11821251
11831252 private doDelete ( ) {
0 commit comments