66import { URI } from 'vs/base/common/uri' ;
77import { isEqual } from 'vs/base/common/extpath' ;
88import { posix } from 'vs/base/common/path' ;
9- import * as resources from 'vs/base/common/resources' ;
109import { ResourceMap } from 'vs/base/common/map' ;
1110import { IFileStat , IFileService , FileSystemProviderCapabilities } from 'vs/platform/files/common/files' ;
1211import { rtrim , startsWithIgnoreCase , startsWith , equalsIgnoreCase } from 'vs/base/common/strings' ;
@@ -16,16 +15,20 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1615import { memoize } from 'vs/base/common/decorators' ;
1716import { Emitter , Event } from 'vs/base/common/event' ;
1817import { IExplorerService } from 'vs/workbench/contrib/files/common/files' ;
18+ import { joinPath , isEqualOrParent , basenameOrAuthority } from 'vs/base/common/resources' ;
1919
2020export class ExplorerModel implements IDisposable {
2121
2222 private _roots ! : ExplorerItem [ ] ;
2323 private _listener : IDisposable ;
2424 private readonly _onDidChangeRoots = new Emitter < void > ( ) ;
2525
26- constructor ( private readonly contextService : IWorkspaceContextService ) {
26+ constructor (
27+ private readonly contextService : IWorkspaceContextService ,
28+ explorerService : IExplorerService
29+ ) {
2730 const setRoots = ( ) => this . _roots = this . contextService . getWorkspace ( ) . folders
28- . map ( folder => new ExplorerItem ( folder . uri , undefined , true , false , false , folder . name ) ) ;
31+ . map ( folder => new ExplorerItem ( folder . uri , explorerService , undefined , true , false , false , folder . name ) ) ;
2932 setRoots ( ) ;
3033
3134 this . _listener = this . contextService . onDidChangeWorkspaceFolders ( ( ) => {
@@ -80,11 +83,12 @@ export class ExplorerItem {
8083
8184 constructor (
8285 public resource : URI ,
86+ private readonly explorerService : IExplorerService ,
8387 private _parent : ExplorerItem | undefined ,
8488 private _isDirectory ?: boolean ,
8589 private _isSymbolicLink ?: boolean ,
8690 private _isReadonly ?: boolean ,
87- private _name : string = resources . basenameOrAuthority ( resource ) ,
91+ private _name : string = basenameOrAuthority ( resource ) ,
8892 private _mtime ?: number ,
8993 ) {
9094 this . _isDirectoryResolved = false ;
@@ -154,8 +158,8 @@ export class ExplorerItem {
154158 return this === this . root ;
155159 }
156160
157- static create ( service : IFileService , raw : IFileStat , parent : ExplorerItem | undefined , resolveTo ?: readonly URI [ ] ) : ExplorerItem {
158- const stat = new ExplorerItem ( raw . resource , parent , raw . isDirectory , raw . isSymbolicLink , service . hasCapability ( raw . resource , FileSystemProviderCapabilities . Readonly ) , raw . name , raw . mtime ) ;
161+ static create ( explorerService : IExplorerService , fileService : IFileService , raw : IFileStat , parent : ExplorerItem | undefined , resolveTo ?: readonly URI [ ] ) : ExplorerItem {
162+ const stat = new ExplorerItem ( raw . resource , explorerService , parent , raw . isDirectory , raw . isSymbolicLink , fileService . hasCapability ( raw . resource , FileSystemProviderCapabilities . Readonly ) , raw . name , raw . mtime ) ;
159163
160164 // Recursively add children if present
161165 if ( stat . isDirectory ) {
@@ -164,13 +168,13 @@ export class ExplorerItem {
164168 // the folder is fully resolved if either it has a list of children or the client requested this by using the resolveTo
165169 // array of resource path to resolve.
166170 stat . _isDirectoryResolved = ! ! raw . children || ( ! ! resolveTo && resolveTo . some ( ( r ) => {
167- return resources . isEqualOrParent ( r , stat . resource ) ;
171+ return isEqualOrParent ( r , stat . resource ) ;
168172 } ) ) ;
169173
170174 // Recurse into children
171175 if ( raw . children ) {
172176 for ( let i = 0 , len = raw . children . length ; i < len ; i ++ ) {
173- const child = ExplorerItem . create ( service , raw . children [ i ] , stat , resolveTo ) ;
177+ const child = ExplorerItem . create ( explorerService , fileService , raw . children [ i ] , stat , resolveTo ) ;
174178 stat . addChild ( child ) ;
175179 }
176180 }
@@ -262,7 +266,7 @@ export class ExplorerItem {
262266 const resolveMetadata = explorerService . sortOrder === 'modified' ;
263267 try {
264268 const stat = await fileService . resolve ( this . resource , { resolveSingleChildDescendants : true , resolveMetadata } ) ;
265- const resolved = ExplorerItem . create ( fileService , stat , this ) ;
269+ const resolved = ExplorerItem . create ( explorerService , fileService , stat , this ) ;
266270 ExplorerItem . mergeLocalWithDisk ( resolved , this ) ;
267271 } catch ( e ) {
268272 this . isError = true ;
@@ -302,7 +306,7 @@ export class ExplorerItem {
302306 }
303307
304308 private getPlatformAwareName ( name : string ) : string {
305- return ( ! name || ! resources . hasToIgnoreCase ( this . resource ) ) ? name : name . toLowerCase ( ) ;
309+ return this . explorerService . shouldIgnoreCase ( this . resource ) ? name . toLowerCase ( ) : name ;
306310 }
307311
308312 /**
@@ -319,7 +323,7 @@ export class ExplorerItem {
319323
320324 private updateResource ( recursive : boolean ) : void {
321325 if ( this . _parent ) {
322- this . resource = resources . joinPath ( this . _parent . resource , this . name ) ;
326+ this . resource = joinPath ( this . _parent . resource , this . name ) ;
323327 }
324328
325329 if ( recursive ) {
@@ -352,16 +356,17 @@ export class ExplorerItem {
352356 find ( resource : URI ) : ExplorerItem | null {
353357 // Return if path found
354358 // For performance reasons try to do the comparison as fast as possible
359+ const ignoreCase = this . explorerService . shouldIgnoreCase ( resource ) ;
355360 if ( resource && this . resource . scheme === resource . scheme && equalsIgnoreCase ( this . resource . authority , resource . authority ) &&
356- ( resources . hasToIgnoreCase ( resource ) ? startsWithIgnoreCase ( resource . path , this . resource . path ) : startsWith ( resource . path , this . resource . path ) ) ) {
357- return this . findByPath ( rtrim ( resource . path , posix . sep ) , this . resource . path . length ) ;
361+ ( ignoreCase ? startsWithIgnoreCase ( resource . path , this . resource . path ) : startsWith ( resource . path , this . resource . path ) ) ) {
362+ return this . findByPath ( rtrim ( resource . path , posix . sep ) , this . resource . path . length , ignoreCase ) ;
358363 }
359364
360365 return null ; //Unable to find
361366 }
362367
363- private findByPath ( path : string , index : number ) : ExplorerItem | null {
364- if ( isEqual ( rtrim ( this . resource . path , posix . sep ) , path , resources . hasToIgnoreCase ( this . resource ) ) ) {
368+ private findByPath ( path : string , index : number , ignoreCase : boolean ) : ExplorerItem | null {
369+ if ( isEqual ( rtrim ( this . resource . path , posix . sep ) , path , ignoreCase ) ) {
365370 return this ;
366371 }
367372
@@ -383,7 +388,7 @@ export class ExplorerItem {
383388
384389 if ( child ) {
385390 // We found a child with the given name, search inside it
386- return child . findByPath ( path , indexOfNextSep ) ;
391+ return child . findByPath ( path , indexOfNextSep , ignoreCase ) ;
387392 }
388393 }
389394
@@ -392,7 +397,7 @@ export class ExplorerItem {
392397}
393398
394399export class NewExplorerItem extends ExplorerItem {
395- constructor ( parent : ExplorerItem , isDirectory : boolean ) {
396- super ( URI . file ( '' ) , parent , isDirectory ) ;
400+ constructor ( explorerService : IExplorerService , parent : ExplorerItem , isDirectory : boolean ) {
401+ super ( URI . file ( '' ) , explorerService , parent , isDirectory ) ;
397402 }
398403}
0 commit comments