@@ -40,6 +40,7 @@ export class RemoteFileDialog {
4040 private remoteAuthority : string | undefined ;
4141 private requiresTrailing : boolean ;
4242 private userValue : string ;
43+ private scheme : string = REMOTE_HOST_SCHEME ;
4344
4445 constructor (
4546 @IFileService private readonly remoteFileService : RemoteFileService ,
@@ -56,9 +57,9 @@ export class RemoteFileDialog {
5657 }
5758
5859 public async showOpenDialog ( options : IOpenDialogOptions = { } ) : Promise < IURIToOpen [ ] | undefined > {
59- const defaultUri = options . defaultUri ? options . defaultUri : URI . from ( { scheme : REMOTE_HOST_SCHEME , authority : this . remoteAuthority , path : '/' } ) ;
60- if ( ! this . remoteFileService . canHandleResource ( defaultUri ) ) {
61- this . notificationService . info ( nls . localize ( 'remoteFileDialog.notConnectedToRemote' , 'File system provider for {0} is not available.' , defaultUri . toString ( ) ) ) ;
60+ this . scheme = options . defaultUri . scheme ;
61+ const newOptions = this . getOptions ( options ) ;
62+ if ( ! newOptions ) {
6263 return Promise . resolve ( undefined ) ;
6364 }
6465
@@ -67,9 +68,7 @@ export class RemoteFileDialog {
6768 const openFileFolderString = nls . localize ( 'remoteFileDialog.localFileFolderFallback' , 'Open Local File or Folder' ) ;
6869 let tooltip = options . canSelectFiles ? ( options . canSelectFolders ? openFileFolderString : openFileString ) : openFolderString ;
6970 this . fallbackPickerButton = { iconPath : this . getDialogIcons ( 'folder' ) , tooltip } ;
70- const remoteOptions : IOpenDialogOptions = objects . deepClone ( options ) ;
71- remoteOptions . defaultUri = defaultUri ;
72- return this . pickResource ( remoteOptions ) . then ( async fileFolderUri => {
71+ return this . pickResource ( newOptions ) . then ( async fileFolderUri => {
7372 if ( fileFolderUri ) {
7473 const stat = await this . remoteFileService . resolveFile ( fileFolderUri ) ;
7574 return < IURIToOpen [ ] > [ { uri : fileFolderUri , typeHint : stat . isDirectory ? 'folder' : 'file' } ] ;
@@ -80,26 +79,38 @@ export class RemoteFileDialog {
8079 }
8180
8281 public showSaveDialog ( options : ISaveDialogOptions ) : Promise < URI | undefined > {
82+ this . scheme = options . defaultUri . scheme ;
8383 this . requiresTrailing = true ;
84- const defaultUri = options . defaultUri ? options . defaultUri : URI . from ( { scheme : REMOTE_HOST_SCHEME , authority : this . remoteAuthority , path : '/' } ) ;
85- if ( ! this . remoteFileService . canHandleResource ( defaultUri ) ) {
86- this . notificationService . info ( nls . localize ( 'remoteFileDialog.notConnectedToRemote' , 'File system provider for {0} is not available.' , defaultUri . toString ( ) ) ) ;
84+ const newOptions = this . getOptions ( options ) ;
85+ if ( ! newOptions ) {
8786 return Promise . resolve ( undefined ) ;
8887 }
8988 this . fallbackPickerButton = { iconPath : this . getDialogIcons ( 'folder' ) , tooltip : nls . localize ( 'remoteFileDialog.localSaveFallback' , 'Save Local File' ) } ;
90- const remoteOptions : IOpenDialogOptions = objects . deepClone ( options ) ;
91- remoteOptions . defaultUri = resources . dirname ( defaultUri ) ;
92- remoteOptions . canSelectFolders = true ;
93- remoteOptions . canSelectFiles = true ;
89+ newOptions . canSelectFolders = true ;
90+ newOptions . canSelectFiles = true ;
91+ const filename = resources . basename ( newOptions . defaultUri ) ;
92+ newOptions . defaultUri = resources . dirname ( newOptions . defaultUri ) ;
9493 return new Promise < URI | undefined > ( ( resolve ) => {
95- this . pickResource ( remoteOptions , resources . basename ( defaultUri ) ) . then ( folderUri => {
94+ this . pickResource ( newOptions , filename ) . then ( folderUri => {
9695 resolve ( folderUri ) ;
9796 } ) ;
9897 } ) ;
9998 }
10099
100+ private getOptions ( options : ISaveDialogOptions | IOpenDialogOptions ) : IOpenDialogOptions | undefined {
101+ const defaultUri = options . defaultUri ? options . defaultUri : URI . from ( { scheme : REMOTE_HOST_SCHEME , authority : this . remoteAuthority , path : '/' } ) ;
102+ if ( ! this . remoteFileService . canHandleResource ( defaultUri ) ) {
103+ this . notificationService . info ( nls . localize ( 'remoteFileDialog.notConnectedToRemote' , 'File system provider for {0} is not available.' , defaultUri . toString ( ) ) ) ;
104+ return undefined ;
105+ }
106+ const newOptions : IOpenDialogOptions = objects . deepClone ( options ) ;
107+ newOptions . defaultUri = defaultUri ;
108+ return newOptions ;
109+ }
110+
101111 private remoteUriFrom ( path : string ) : URI {
102- return URI . from ( { scheme : REMOTE_HOST_SCHEME , authority : this . remoteAuthority , path } ) ;
112+ path = path . replace ( / \\ / g, '/' ) ;
113+ return URI . from ( { scheme : this . scheme , authority : this . remoteAuthority , path } ) ;
103114 }
104115
105116 private async pickResource ( options : IOpenDialogOptions , trailing ?: string ) : Promise < URI | undefined > {
@@ -149,7 +160,7 @@ export class RemoteFileDialog {
149160 } ) ;
150161
151162 this . filePickBox . title = options . title ;
152- this . filePickBox . value = this . labelService . getUriLabel ( this . currentFolder ) ;
163+ this . filePickBox . value = this . pathFromUri ( this . currentFolder ) ;
153164 this . filePickBox . items = [ ] ;
154165 this . filePickBox . onDidAccept ( _ => {
155166 if ( isAcceptHandled || this . filePickBox . busy ) {
@@ -169,12 +180,12 @@ export class RemoteFileDialog {
169180 isAcceptHandled = false ;
170181 } ) ;
171182
172- this . filePickBox . onDidChangeValue ( value => {
183+ this . filePickBox . onDidChangeValue ( async value => {
173184 if ( value !== this . userValue ) {
174185 const trimmedPickBoxValue = ( ( this . filePickBox . value . length > 1 ) && this . endsWithSlash ( this . filePickBox . value ) ) ? this . filePickBox . value . substr ( 0 , this . filePickBox . value . length - 1 ) : this . filePickBox . value ;
175186 const valueUri = this . remoteUriFrom ( trimmedPickBoxValue ) ;
176187 if ( ! resources . isEqual ( this . currentFolder , valueUri ) ) {
177- this . tryUpdateItems ( value , valueUri ) ;
188+ await this . tryUpdateItems ( value , valueUri ) ;
178189 }
179190 this . setActiveItems ( value ) ;
180191 this . userValue = value ;
@@ -327,7 +338,7 @@ export class RemoteFileDialog {
327338
328339 private updateItems ( newFolder : URI , trailing ?: string ) {
329340 this . currentFolder = newFolder ;
330- this . filePickBox . value = trailing ? this . labelService . getUriLabel ( resources . joinPath ( newFolder , trailing ) ) : this . labelService . getUriLabel ( newFolder , { endWithSeparator : true } ) ;
341+ this . filePickBox . value = trailing ? this . pathFromUri ( resources . joinPath ( newFolder , trailing ) ) : this . pathFromUri ( newFolder , true ) ;
331342 this . filePickBox . busy = true ;
332343 this . createItems ( this . currentFolder ) . then ( items => {
333344 this . filePickBox . items = items ;
@@ -338,6 +349,15 @@ export class RemoteFileDialog {
338349 } ) ;
339350 }
340351
352+ private pathFromUri ( uri : URI , endWithSeparator : boolean = false ) : string {
353+ const sep = this . labelService . getSeparator ( uri . scheme , uri . authority ) ;
354+ let result = uri . fsPath . replace ( / \/ / g, sep ) ;
355+ if ( endWithSeparator && ! this . endsWithSlash ( result ) ) {
356+ result = result + sep ;
357+ }
358+ return result ;
359+ }
360+
341361 private isValidBaseName ( name : string ) : boolean {
342362 if ( ! name || name . length === 0 || / ^ \s + $ / . test ( name ) ) {
343363 return false ; // require a name that is not just whitespace
@@ -372,8 +392,8 @@ export class RemoteFileDialog {
372392 }
373393
374394 private basenameWithTrailingSlash ( fullPath : URI ) : string {
375- const child = this . labelService . getUriLabel ( fullPath , { endWithSeparator : true } ) ;
376- const parent = this . labelService . getUriLabel ( resources . dirname ( fullPath ) , { endWithSeparator : true } ) ;
395+ const child = this . pathFromUri ( fullPath , true ) ;
396+ const parent = this . pathFromUri ( resources . dirname ( fullPath ) , true ) ;
377397 return child . substring ( parent . length ) ;
378398 }
379399
0 commit comments