Skip to content

Commit

Permalink
fix: Manually change focus & selection when right clicked on tree items
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Mar 26, 2024
1 parent af7a746 commit 7c8f1c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions biscuit/core/components/utils/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ def collapse_all(self) -> None:
def delete(self, *a, **kw) -> None:
self.tree.delete(*a, *kw)

def focus(self) -> str:
return self.tree.focus() or ''
def focus(self, *args) -> str:
return self.tree.focus(*args) or ''

def get_children(self, *a, **kw) -> str:
return self.tree.get_children(*a, **kw)

def identify_row(self, y) -> str:
return self.tree.identify_row(y)

def insert(self, *args, **kwargs):
return self.tree.insert(*args, **kwargs)

Expand All @@ -82,6 +85,9 @@ def parent_selected(self):

def selected_parent_path(self):
return self.item_fullpath(self.parent_selected())

def selection_set(self, *args, **kwargs):
return self.tree.selection_set(*args, **kwargs)

def selected_path(self):
return self.item_fullpath(self.focus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ def __init__(self, master, startpath=None, observe_changes=False, itembar=True,
self.loading = False

self.ctxmenu = ExplorerContextMenu(self, "ExplorerContextMenu")
self.tree.bind('<Button-3>', self.ctxmenu.show)
self.tree.bind('<Button-3>', self.right_click)

if startpath:
self.change_path(startpath)
else:
self.tree.insert('', 0, text='You have not yet opened a folder.')

def right_click(self, e: tk.Event) -> None:
if item := self.tree.identify_row(e.y):
self.tree.selection_set(item)
self.tree.focus(item)
self.ctxmenu.show(e)

# IMPORTANT
def change_path(self, path: str) -> None:
Expand Down

0 comments on commit 7c8f1c6

Please sign in to comment.