@@ -36,10 +36,9 @@ def sort_nicely(names):
36
36
Source: http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
37
37
"""
38
38
convert = lambda text : int (text ) if text .isdigit () else text .lower ()
39
- alphanum_key = lambda key : [convert (c ) for c in re .split ('([0-9]+)' , key )]
39
+ alphanum_key = lambda key : [convert (c ) for c in re .split ('([0-9]+)' , key [ 'file' ] if key [ 'file' ] else key )]
40
40
names .sort (key = alphanum_key )
41
41
42
-
43
42
def print (* args , ** kwargs ):
44
43
""" Redefine print() function; the reason is the inconsistent treatment of
45
44
unicode literals among Python versions used in ST2.
@@ -400,54 +399,76 @@ def prepare_filelist(self, names, path, goto, indent):
400
399
items += files
401
400
return items
402
401
403
- def is_hidden (self , filename , path , goto = '' ):
402
+ def is_hidden (self , filename , path , goto = '' , get_is_dir = False , dirs_only = False ):
404
403
if not (path or goto ): # special case for ThisPC
405
404
return False
406
- tests = self .view .settings ().get ('dired_hidden_files_patterns' , ['.*' ])
407
- if isinstance (tests , str ):
408
- tests = [tests ]
409
- if any (fnmatch .fnmatch (filename , pattern ) for pattern in tests ):
410
- return True
411
- if sublime .platform () != 'windows' :
412
- return False
413
- # check for attribute on windows:
414
- try :
415
- attrs = ctypes .windll .kernel32 .GetFileAttributesW (join (path , goto , filename ))
416
- assert attrs != - 1
417
- result = bool (attrs & 2 )
418
- except (AttributeError , AssertionError ):
419
- result = False
420
- return result
421
-
422
- def try_listing_directory (self , path ):
405
+ show_hidden = self .show_hidden
406
+ show_excluded = self .view .settings ().get ('dired_show_excluded_files' , True )
407
+ is_hidden = False
408
+ fullpath = join (path , goto , filename )
409
+ is_dir = isdir (fullpath )
410
+ result = lambda : is_hidden if not get_is_dir else [is_hidden , is_dir ]
411
+ if dirs_only and not is_dir :
412
+ return result ()
413
+ if not is_hidden and not show_excluded :
414
+ if is_dir :
415
+ tests = self .view .settings ().get ('folder_exclude_patterns' , [])
416
+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
417
+ is_hidden = True
418
+ else :
419
+ tests = self .view .settings ().get ('file_exclude_patterns' , [])
420
+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
421
+ is_hidden = True
422
+ if not is_hidden and not show_hidden :
423
+ tests = self .view .settings ().get ('dired_hidden_files_patterns' , ['.*' ])
424
+ if isinstance (tests , str ):
425
+ tests = [tests ]
426
+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
427
+ is_hidden = True
428
+ if not is_hidden and NT :
429
+ # check for attribute on windows:
430
+ try :
431
+ attrs = ctypes .windll .kernel32 .GetFileAttributesW (fullpath )
432
+ assert attrs != - 1
433
+ if bool (attrs & 2 ):
434
+ is_hidden = True
435
+ except :
436
+ pass
437
+ return result ()
438
+
439
+ def listdir (self , path ):
440
+ return [{"file" : file , "isdir" : isdir (join (path , file ))} for file in os .listdir (path )]
441
+
442
+ def listdir_only_dirs (self , path ):
443
+ return [item for item in self .listdir (path ) if item ["isdir" ] == True ]
444
+
445
+ def try_listing_directory (self , path , dirs_only = False ):
423
446
'''Return tuple of two element
424
447
items sorted list of filenames in path, or empty list
425
448
error exception message, or empty string
426
449
'''
427
- items , error = [], ''
450
+ items = []
451
+ error = None
428
452
try :
429
- if not self . show_hidden :
430
- items = [ name for name in os . listdir ( path ) if not self .is_hidden ( name , path )]
453
+ if dirs_only :
454
+ items = self .listdir_only_dirs ( path )
431
455
else :
432
- items = os .listdir (path )
456
+ items = self .listdir (path )
433
457
except OSError as e :
434
458
error = str (e )
435
459
if NT :
436
460
error = error .split (':' )[0 ].replace ('[Error 5] ' , 'Access denied' ).replace ('[Error 3] ' , 'Not exists, press r to refresh' )
437
461
if not ST3 and LIN :
438
462
error = error .decode ('utf8' )
439
- else :
463
+ if (error == None ):
464
+ items = [item for item in items if not self .is_hidden (item ['file' ], path )]
440
465
sort_nicely (items )
441
- finally :
442
- return items , error
466
+ return items , error
443
467
444
468
def try_listing_only_dirs (self , path ):
445
469
'''Same as self.try_listing_directory, but items contains only directories.
446
470
Used for prompt completion'''
447
- items , error = self .try_listing_directory (path )
448
- if items :
449
- items = [n for n in items if isdir (join (path , n ))]
450
- return (items , error )
471
+ return self .try_listing_directory (path , dirs_only = True )
451
472
452
473
def restore_marks (self , marked = None ):
453
474
if marked :
0 commit comments