Skip to content

Commit 60cf9ab

Browse files
committed
Keep default drive for SelectDirectoryTreeScreen as home.
1 parent 22c9beb commit 60cf9ab

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

datashuttle/tui/screens/modal_dialogs.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import TYPE_CHECKING, Callable, Optional
4+
from typing import TYPE_CHECKING, Callable
55

66
if TYPE_CHECKING:
77
from pathlib import Path
@@ -219,9 +219,7 @@ class SelectDirectoryTreeScreen(ModalScreen):
219219
220220
"""
221221

222-
def __init__(
223-
self, mainwindow: TuiApp, path_: Optional[Path] = None
224-
) -> None:
222+
def __init__(self, mainwindow: TuiApp) -> None:
225223
"""Initialise SelectDirectoryTreeScreen.
226224
227225
Parameters
@@ -236,12 +234,14 @@ def __init__(
236234
super(SelectDirectoryTreeScreen, self).__init__()
237235
self.mainwindow = mainwindow
238236

239-
if path_ is None:
240-
path_ = Path().home()
241-
self.path_ = path_
237+
self.path_ = Path().home()
242238

243239
self.click_info = ClickInfo()
244240

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,10 +305,13 @@ 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-
self.path_ = Path(event.value)
309-
self.query_one(
310-
"#select_directory_tree_directory_tree"
311-
).path = self.path_
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_
312315

313316
@require_double_click
314317
def on_directory_tree_directory_selected(

0 commit comments

Comments
 (0)