Skip to content

Commit 486ca12

Browse files
committed
how about this?
1 parent 6b8365e commit 486ca12

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

common.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,44 +400,54 @@ def prepare_filelist(self, names, path, goto, indent):
400400
items += files
401401
return items
402402

403-
def is_hidden(self, filename, path, goto=''):
403+
def is_hidden(self, filename, path, goto='', get_is_dir=False, dirs_only=False):
404404
if not (path or goto): # special case for ThisPC
405405
return False
406406
show_hidden = self.show_hidden
407407
show_excluded = self.view.settings().get('dired_show_excluded_files', True)
408408
is_hidden = False
409-
if not show_hidden:
409+
fullpath = join(path, goto, filename)
410+
is_dir = isdir(fullpath)
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:
410424
tests = self.view.settings().get('dired_hidden_files_patterns', ['.*'])
411425
if isinstance(tests, str):
412426
tests = [tests]
413427
if any(fnmatch.fnmatch(filename, p) for p in tests):
414428
is_hidden = True
415-
if sublime.platform() == 'windows':
429+
if not is_hidden and sublime.platform() == 'windows':
416430
# check for attribute on windows:
417431
try:
418-
attrs = ctypes.windll.kernel32.GetFileAttributesW(join(path, goto, filename))
432+
attrs = ctypes.windll.kernel32.GetFileAttributesW(fullpath)
419433
assert attrs != -1
420434
if bool(attrs & 2):
421435
is_hidden = True
422436
except:
423437
pass
424-
if not show_excluded:
425-
tests = self.view.settings().get('folder_exclude_patterns', []) + self.view.settings().get('file_exclude_patterns', [])
426-
if any(fnmatch.fnmatch(filename, p) for p in tests):
427-
is_hidden = True
428-
return is_hidden
438+
return result()
429439

430-
def try_listing_directory(self, path):
440+
def try_listing_directory(self, path, dirs_only=False):
431441
'''Return tuple of two element
432442
items sorted list of filenames in path, or empty list
433443
error exception message, or empty string
434444
'''
435445
items, error = [], ''
436446
try:
437-
if not self.show_hidden:
438-
items = [name for name in os.listdir(path) if not self.is_hidden(name, path)]
447+
if dirs_only:
448+
items = [name for name in os.listdir(path) if self.is_hidden(name, path, get_is_dir=True) == (False, False)]
439449
else:
440-
items = os.listdir(path)
450+
items = [name for name in os.listdir(path) if not self.is_hidden(name, path)]
441451
except OSError as e:
442452
error = str(e)
443453
if NT:
@@ -452,9 +462,7 @@ def try_listing_directory(self, path):
452462
def try_listing_only_dirs(self, path):
453463
'''Same as self.try_listing_directory, but items contains only directories.
454464
Used for prompt completion'''
455-
items, error = self.try_listing_directory(path)
456-
if items:
457-
items = [n for n in items if isdir(join(path, n))]
465+
items, error = self.try_listing_directory(path, dirs_only=True)
458466
return (items, error)
459467

460468
def restore_marks(self, marked=None):

0 commit comments

Comments
 (0)