@@ -36,10 +36,9 @@ def sort_nicely(names):
3636 Source: http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
3737 """
3838 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 )]
4040 names .sort (key = alphanum_key )
4141
42-
4342def print (* args , ** kwargs ):
4443 """ Redefine print() function; the reason is the inconsistent treatment of
4544 unicode literals among Python versions used in ST2.
@@ -400,54 +399,77 @@ def prepare_filelist(self, names, path, goto, indent):
400399 items += files
401400 return items
402401
403- def is_hidden (self , filename , path , goto = '' ):
402+ def is_hidden (self , item , path , goto = '' , get_is_dir = False , dirs_only = False ):
404403 if not (path or goto ): # special case for ThisPC
405404 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+ filename = item ['file' ]
409+ fullpath = join (path , goto , filename )
410+ is_dir = item ['is_dir' ]
411+ result = lambda : is_hidden if not get_is_dir else [is_hidden , is_dir ]
412+ if dirs_only and not is_dir :
413+ return result ()
414+ if not is_hidden and not show_excluded :
415+ if is_dir :
416+ tests = self .view .settings ().get ('folder_exclude_patterns' , [])
417+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
418+ is_hidden = True
419+ else :
420+ tests = self .view .settings ().get ('file_exclude_patterns' , [])
421+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
422+ is_hidden = True
423+ if not is_hidden and not show_hidden :
424+ tests = self .view .settings ().get ('dired_hidden_files_patterns' , ['.*' ])
425+ if isinstance (tests , str ):
426+ tests = [tests ]
427+ if any (fnmatch .fnmatch (filename , p ) for p in tests ):
428+ is_hidden = True
429+ if not is_hidden and NT :
430+ # check for attribute on windows:
431+ try :
432+ attrs = ctypes .windll .kernel32 .GetFileAttributesW (fullpath )
433+ assert attrs != - 1
434+ if bool (attrs & 2 ):
435+ is_hidden = True
436+ except :
437+ pass
438+ return result ()
439+
440+ def listdir (self , path ):
441+ return [{'file' : file , 'is_dir' : isdir (join (path , file ))} for file in os .listdir (path )]
442+
443+ def listdir_only_dirs (self , path ):
444+ return [item for item in self .listdir (path ) if item ["isdir" ] == True ]
445+
446+ def try_listing_directory (self , path , dirs_only = False ):
423447 '''Return tuple of two element
424448 items sorted list of filenames in path, or empty list
425449 error exception message, or empty string
426450 '''
427- items , error = [], ''
451+ items = []
452+ error = None
428453 try :
429- if not self . show_hidden :
430- items = [ name for name in os . listdir ( path ) if not self .is_hidden ( name , path )]
454+ if dirs_only :
455+ items = self .listdir_only_dirs ( path )
431456 else :
432- items = os .listdir (path )
457+ items = self .listdir (path )
433458 except OSError as e :
434459 error = str (e )
435460 if NT :
436461 error = error .split (':' )[0 ].replace ('[Error 5] ' , 'Access denied' ).replace ('[Error 3] ' , 'Not exists, press r to refresh' )
437462 if not ST3 and LIN :
438463 error = error .decode ('utf8' )
439- else :
464+ if (error == None ):
465+ items = [item for item in items if not self .is_hidden (item , path )]
440466 sort_nicely (items )
441- finally :
442- return items , error
467+ return items , error
443468
444469 def try_listing_only_dirs (self , path ):
445470 '''Same as self.try_listing_directory, but items contains only directories.
446471 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 )
472+ return self .try_listing_directory (path , dirs_only = True )
451473
452474 def restore_marks (self , marked = None ):
453475 if marked :
0 commit comments