Skip to content

Commit

Permalink
fix: Bugs with directory tree watcher fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jun 23, 2024
1 parent 6ccc21a commit f199ec8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/biscuit/common/ui/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def identify_row(self, y) -> str:
return self.tree.identify_row(y)

def insert(self, *args, **kwargs):
return self.tree.insert(*args, **kwargs)
try:
return self.tree.insert(*args, **kwargs)
except tk.TclError:
return None

def add(self, *a, **kw):
return self.tree.insert("", "end", *a, **kw)
Expand Down
17 changes: 8 additions & 9 deletions src/biscuit/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def open(self, path: str, warn_for_directory=False) -> None:
return

if os.path.isdir(path):
self.open_directory(path)
return self.explorer.directory.refresh_root()
return self.open_directory(path)

if os.path.isfile(path):
return self.open_editor(path)
Expand All @@ -79,20 +78,20 @@ def open_directory(self, dir: str) -> None:

self.active_directory = dir

try:
self.git.check_git()
self.update_git()
except Exception as e:
self.logger.error(f"Checking git failed: {e}")
self.notifications.error("Checking git failed: see logs")

self.explorer.directory.change_path(dir)
self.set_title(os.path.basename(self.active_directory))

self.editorsmanager.delete_all_editors()
self.terminalmanager.delete_all_terminals()
self.terminalmanager.open_terminal()

try:
self.git.check_git()
self.update_git()
except Exception as e:
self.logger.error(f"Checking git failed: {e}")
self.notifications.error("Checking git failed: see logs")

self.event_generate("<<DirectoryChanged>>", data=dir)

def update_git(self) -> None:
Expand Down
50 changes: 29 additions & 21 deletions src/biscuit/views/explorer/directorytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,42 @@ def update_treeview(self, parent_path: str, parent="") -> None:
if name in self.hide_dirs:
continue

node = self.tree.insert(
parent or "",
"end",
text=f" {name}",
values=[path, "directory"],
# image="foldericon",
open=False,
tags="ignored" if unixlike in ignored else "",
)
self.nodes[os.path.abspath(path)] = node
self.tree.insert(node, "end", text="loading...", tags="ignored")
try:
node = self.tree.insert(
parent or "",
"end",
text=f" {name}",
values=[path, "directory"],
# image="foldericon",
open=False,
tags="ignored" if unixlike in ignored else "",
)
self.nodes[os.path.abspath(path)] = node
self.tree.insert(node, "end", text="loading...", tags="ignored")
except:
self.refresh_root()
break

# NOTE: recursive mode loading (not good for large projects)
# self.update_treeview(path, node)
else:
if name.split(".")[-1] in self.ignore_exts:
continue

# TODO check filetype and get matching icon, cases
node = self.tree.insert(
parent,
"end",
text=f" {name}",
values=[path, "file"],
image="document",
tags="ignored" if unixlike in ignored else "",
)
self.nodes[os.path.abspath(path)] = node
try:
# TODO check filetype and get matching icon, cases
node = self.tree.insert(
parent,
"end",
text=f" {name}",
values=[path, "file"],
image="document",
tags="ignored" if unixlike in ignored else "",
)
self.nodes[os.path.abspath(path)] = node
except:
self.refresh_root()
break

def selected_directory(self) -> str:
"""Returns the selected directory path, or the current path if no directory is selected."""
Expand Down

0 comments on commit f199ec8

Please sign in to comment.