6
6
import { URI } from 'vs/base/common/uri' ;
7
7
import { isEqual } from 'vs/base/common/extpath' ;
8
8
import { posix } from 'vs/base/common/path' ;
9
- import * as resources from 'vs/base/common/resources' ;
10
9
import { ResourceMap } from 'vs/base/common/map' ;
11
10
import { IFileStat , IFileService , FileSystemProviderCapabilities } from 'vs/platform/files/common/files' ;
12
11
import { rtrim , startsWithIgnoreCase , startsWith , equalsIgnoreCase } from 'vs/base/common/strings' ;
@@ -16,16 +15,20 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
16
15
import { memoize } from 'vs/base/common/decorators' ;
17
16
import { Emitter , Event } from 'vs/base/common/event' ;
18
17
import { IExplorerService } from 'vs/workbench/contrib/files/common/files' ;
18
+ import { joinPath , isEqualOrParent , basenameOrAuthority } from 'vs/base/common/resources' ;
19
19
20
20
export class ExplorerModel implements IDisposable {
21
21
22
22
private _roots ! : ExplorerItem [ ] ;
23
23
private _listener : IDisposable ;
24
24
private readonly _onDidChangeRoots = new Emitter < void > ( ) ;
25
25
26
- constructor ( private readonly contextService : IWorkspaceContextService ) {
26
+ constructor (
27
+ private readonly contextService : IWorkspaceContextService ,
28
+ explorerService : IExplorerService
29
+ ) {
27
30
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 ) ) ;
29
32
setRoots ( ) ;
30
33
31
34
this . _listener = this . contextService . onDidChangeWorkspaceFolders ( ( ) => {
@@ -80,11 +83,12 @@ export class ExplorerItem {
80
83
81
84
constructor (
82
85
public resource : URI ,
86
+ private readonly explorerService : IExplorerService ,
83
87
private _parent : ExplorerItem | undefined ,
84
88
private _isDirectory ?: boolean ,
85
89
private _isSymbolicLink ?: boolean ,
86
90
private _isReadonly ?: boolean ,
87
- private _name : string = resources . basenameOrAuthority ( resource ) ,
91
+ private _name : string = basenameOrAuthority ( resource ) ,
88
92
private _mtime ?: number ,
89
93
) {
90
94
this . _isDirectoryResolved = false ;
@@ -154,8 +158,8 @@ export class ExplorerItem {
154
158
return this === this . root ;
155
159
}
156
160
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 ) ;
159
163
160
164
// Recursively add children if present
161
165
if ( stat . isDirectory ) {
@@ -164,13 +168,13 @@ export class ExplorerItem {
164
168
// the folder is fully resolved if either it has a list of children or the client requested this by using the resolveTo
165
169
// array of resource path to resolve.
166
170
stat . _isDirectoryResolved = ! ! raw . children || ( ! ! resolveTo && resolveTo . some ( ( r ) => {
167
- return resources . isEqualOrParent ( r , stat . resource ) ;
171
+ return isEqualOrParent ( r , stat . resource ) ;
168
172
} ) ) ;
169
173
170
174
// Recurse into children
171
175
if ( raw . children ) {
172
176
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 ) ;
174
178
stat . addChild ( child ) ;
175
179
}
176
180
}
@@ -262,7 +266,7 @@ export class ExplorerItem {
262
266
const resolveMetadata = explorerService . sortOrder === 'modified' ;
263
267
try {
264
268
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 ) ;
266
270
ExplorerItem . mergeLocalWithDisk ( resolved , this ) ;
267
271
} catch ( e ) {
268
272
this . isError = true ;
@@ -302,7 +306,7 @@ export class ExplorerItem {
302
306
}
303
307
304
308
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 ;
306
310
}
307
311
308
312
/**
@@ -319,7 +323,7 @@ export class ExplorerItem {
319
323
320
324
private updateResource ( recursive : boolean ) : void {
321
325
if ( this . _parent ) {
322
- this . resource = resources . joinPath ( this . _parent . resource , this . name ) ;
326
+ this . resource = joinPath ( this . _parent . resource , this . name ) ;
323
327
}
324
328
325
329
if ( recursive ) {
@@ -352,16 +356,17 @@ export class ExplorerItem {
352
356
find ( resource : URI ) : ExplorerItem | null {
353
357
// Return if path found
354
358
// For performance reasons try to do the comparison as fast as possible
359
+ const ignoreCase = this . explorerService . shouldIgnoreCase ( resource ) ;
355
360
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 ) ;
358
363
}
359
364
360
365
return null ; //Unable to find
361
366
}
362
367
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 ) ) {
365
370
return this ;
366
371
}
367
372
@@ -383,7 +388,7 @@ export class ExplorerItem {
383
388
384
389
if ( child ) {
385
390
// We found a child with the given name, search inside it
386
- return child . findByPath ( path , indexOfNextSep ) ;
391
+ return child . findByPath ( path , indexOfNextSep , ignoreCase ) ;
387
392
}
388
393
}
389
394
@@ -392,7 +397,7 @@ export class ExplorerItem {
392
397
}
393
398
394
399
export 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 ) ;
397
402
}
398
403
}
0 commit comments