11from __future__ import annotations
22
33import asyncio
4- from typing import TYPE_CHECKING , Callable
4+ from typing import TYPE_CHECKING , Callable , Optional
55
66if TYPE_CHECKING :
77 from pathlib import Path
@@ -219,7 +219,9 @@ class SelectDirectoryTreeScreen(ModalScreen):
219219
220220 """
221221
222- def __init__ (self , mainwindow : TuiApp ) -> None :
222+ def __init__ (
223+ self , mainwindow : TuiApp , path_ : Optional [Path ] = None
224+ ) -> None :
223225 """Initialise SelectDirectoryTreeScreen.
224226
225227 Parameters
@@ -234,14 +236,12 @@ def __init__(self, mainwindow: TuiApp) -> None:
234236 super (SelectDirectoryTreeScreen , self ).__init__ ()
235237 self .mainwindow = mainwindow
236238
237- self .path_ = Path ().home ()
239+ if path_ is None :
240+ path_ = Path ().home ()
241+ self .path_ = path_
238242
239243 self .click_info = ClickInfo ()
240244
241- # Flag as the Select triggers `on_select_change` during set up
242- # which results setting tree back to default drive not home.
243- self .skip_first_select_trigger = True
244-
245245 def compose (self ) -> ComposeResult :
246246 """Add widgets to the SelectDirectoryTreeScreen."""
247247 label_message = (
@@ -305,13 +305,10 @@ def get_selected_drive(self) -> str:
305305
306306 def on_select_changed (self , event : Select .Changed ) -> None :
307307 """Update the directory tree when the drive is changed."""
308- if self .skip_first_select_trigger :
309- self .skip_first_select_trigger = False
310- else :
311- self .path_ = Path (event .value )
312- self .query_one (
313- "#select_directory_tree_directory_tree"
314- ).path = self .path_
308+ self .path_ = Path (event .value )
309+ self .query_one (
310+ "#select_directory_tree_directory_tree"
311+ ).path = self .path_
315312
316313 @require_double_click
317314 def on_directory_tree_directory_selected (
0 commit comments