From 8816682254dcb9e71769d732b97338378e36ac3b Mon Sep 17 00:00:00 2001 From: Asugawara Date: Fri, 15 Mar 2024 00:22:34 +0900 Subject: [PATCH] fix bug in load --- pgcs/custom_select.py | 1 + pgcs/file_system/entries.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pgcs/custom_select.py b/pgcs/custom_select.py index 2e6ddd0..7c140f5 100644 --- a/pgcs/custom_select.py +++ b/pgcs/custom_select.py @@ -150,6 +150,7 @@ def _(event: KeyPressEvent) -> None: def custom_select( choices: Dict[str, Entry], max_preview_height: int = 10, **kwargs: Any ) -> str: + print(choices) text_area = TextArea(prompt="QUERY> ", multiline=False) def filter_candidates(choices: List[str]) -> List[Tuple[str, str]]: diff --git a/pgcs/file_system/entries.py b/pgcs/file_system/entries.py index b241af3..9718135 100644 --- a/pgcs/file_system/entries.py +++ b/pgcs/file_system/entries.py @@ -58,13 +58,16 @@ def get(self, entry_name: str, default: Optional[Entry] = None) -> Optional[Entr return self._children.get(entry_name, default) def add(self, entry: Entry) -> None: - if entry.path().startswith(self.path()): + if entry.name and entry.path().startswith(self.path()): if entry.name not in self._children: self._children[entry.name] = entry def load(self, force: bool = False) -> None: - if not self._children or force: + if force: + self._children = {} + if not self._children: for _, dirnames, filenames in gfs.walk(self.path(), maxdepth=1): + print(f"{dirnames=}, {filenames=}") for dirname in dirnames: self.add(Directory(dirname, self)) for filename in filenames: @@ -95,17 +98,21 @@ def get(self, entry_name: str, default: Optional[Entry] = None) -> Optional[Entr return self._children.get(entry_name, default) def add(self, entry: Entry) -> None: - if entry.path().startswith(self.path()): + if entry.name and entry.path().startswith(self.path()): if entry.name not in self._children: self._children[entry.name] = entry def load(self, force: bool = False) -> None: - if not self._children or force: + if force: + self._children = {} + if not self._children: for _, dirnames, filenames in gfs.walk(self.path(), maxdepth=1): for dirname in dirnames: - self.add(Directory(dirname, self)) + if dirname: + self.add(Directory(dirname, self)) for filename in filenames: - self.add(File(filename, self)) + if filename: + self.add(File(filename, self)) def ls(self) -> List[str]: return [entry.path() for entry in self._children.values()]