Hide dotfiles, dotfolders, and backup files in file dialogs

This commit is contained in:
Isaiah Odhner 2023-05-07 21:55:04 -04:00
parent 403e816644
commit 3af12599dd
2 changed files with 7 additions and 2 deletions

View File

@ -1,9 +1,14 @@
import os
from pathlib import Path
from typing import Iterable
from textual.widgets import DirectoryTree
from textual.widgets._tree import TreeNode
from textual.widgets._directory_tree import DirEntry
class EnhancedDirectoryTree(DirectoryTree):
def filter_paths(self, paths: Iterable[Path]) -> Iterable[Path]:
return [path for path in paths if not (path.name.startswith(".") or path.name.endswith("~") or path.name.startswith("~"))]
def expand_to_path(self, target_path: str) -> None:
"""Expand the directory tree to the target path, loading any directories as needed."""
# TODO: os.path.normcase, and maybe os.path.samefile check

View File

@ -2191,8 +2191,8 @@ class PaintApp(App[None]):
# - It may be deleted in a file manager, which should be fine.
# - This also used to happen when opening the backup file corresponding to the current file;
# it got discarded immediately after opening it, since it "belonged" to the now-closed file;
# now that's prevented by checking if the backup file is being opened before discarding it.
# (TODO: also hide backup files in the file dialogs)
# now that's prevented by checking if the backup file is being opened before discarding it,
# and also backup files are now hidden in the file dialogs (though you can type the name manually).
# But if the file to be opened was deleted,
# then it should show an error message (although it would anyways when trying to read the file).
if self.file_path: