mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Switch away from a keyword approach to a dedicated method approach
While descriptive keywords tend to be a preference within the Textual
codebase for many things, this was one of those times where a developer's
code using the library was likely going to read better if there's a switch
to using dedicated methods; this approach means we can just go with "all"
rather than "{action}_all" without needing to shadow a Python builtin.
This also does mirror mount/mount_all too.
This commit is contained in:
@@ -160,7 +160,7 @@ class TreeNode(Generic[TreeDataType]):
|
||||
self._updates += 1
|
||||
|
||||
def _expand(self, expand_all: bool) -> None:
|
||||
"""Mark a node as expanded (its children are shown).
|
||||
"""Mark the node as expanded (its children are shown).
|
||||
|
||||
Args:
|
||||
expand_all: If `True` expand all offspring at all depths.
|
||||
@@ -171,47 +171,51 @@ class TreeNode(Generic[TreeDataType]):
|
||||
for child in self.children:
|
||||
child._expand(expand_all)
|
||||
|
||||
def expand(self, *, all: bool = False) -> None:
|
||||
"""Expand a node (show its children).
|
||||
def expand(self) -> None:
|
||||
"""Expand the node (show its children)."""
|
||||
self._expand(False)
|
||||
self._tree._invalidate()
|
||||
|
||||
Args:
|
||||
all: If `True` expand all offspring at all depths.
|
||||
"""
|
||||
self._expand(all)
|
||||
def expand_all(self) -> None:
|
||||
"""Expand the node (show its children) and all those below it."""
|
||||
self._expand(True)
|
||||
self._tree._invalidate()
|
||||
|
||||
def _collapse(self, collapse_all: bool) -> None:
|
||||
"""Mark a node as collapsed (its children are hidden).
|
||||
"""Mark the node as collapsed (its children are hidden).
|
||||
|
||||
Args:
|
||||
collapse_all: If `True` collapse all offspring at all depths.
|
||||
"""
|
||||
self._expanded = False
|
||||
self._updates += 1
|
||||
if collapse_all:
|
||||
for child in self.children:
|
||||
child._collapse(collapse_all)
|
||||
self._updates += 1
|
||||
|
||||
def collapse(self, *, all: bool = False) -> None:
|
||||
"""Collapse the node (hide children).
|
||||
|
||||
Args:
|
||||
all: If `True` collapse all offspring at all depths.
|
||||
"""
|
||||
self._collapse(all)
|
||||
def collapse(self) -> None:
|
||||
"""Collapse the node (hide its children)."""
|
||||
self._collapse(False)
|
||||
self._tree._invalidate()
|
||||
|
||||
def toggle(self, *, all: bool = False) -> None:
|
||||
"""Toggle the expanded state.
|
||||
def collapse_all(self) -> None:
|
||||
"""Collapse the node (hide its children) and all those below it."""
|
||||
self._collapse(True)
|
||||
self._tree._invalidate()
|
||||
|
||||
Args:
|
||||
all: If `True` set the expanded state of all offspring
|
||||
nodes at all depths to match this node's toggled state.
|
||||
"""
|
||||
def toggle(self) -> None:
|
||||
"""Toggle the node's expanded state."""
|
||||
if self._expanded:
|
||||
self.collapse(all=all)
|
||||
self.collapse()
|
||||
else:
|
||||
self.expand(all=all)
|
||||
self.expand()
|
||||
|
||||
def toggle_all(self) -> None:
|
||||
"""Toggle the node's expanded state and make all those below it match."""
|
||||
if self._expanded:
|
||||
self.collapse_all()
|
||||
else:
|
||||
self.expand_all()
|
||||
|
||||
@property
|
||||
def label(self) -> TextType:
|
||||
|
||||
Reference in New Issue
Block a user