@@ -17,6 +17,7 @@ class PathEditScreen(Screen[None]):
1717 BINDINGS = [
1818 Binding ("enter" , "confirm" , "Confirm path" , priority = True ),
1919 Binding ("escape" , "cancel" , "Cancel" , priority = True ),
20+ Binding ("c" , "cancel" , "Cancel" ),
2021 ]
2122
2223 def __init__ (self , * args , ** kwargs ) -> None : # type: ignore
@@ -35,22 +36,30 @@ def compose(self) -> ComposeResult:
3536 yield self ._directory_tree
3637 yield self ._selected_dir_label
3738 yield Horizontal (
39+ Button ("Cancel" , id = "cancel-button" , variant = "warning" ),
3840 Button ("Confirm" , id = "confirm-button" , variant = "success" ),
3941 id = "path-edit-button-container" ,
4042 )
4143 log .info ("path_edit - Path edit screen composed" )
4244
4345 def on_mount (self ) -> None :
44- self ._selected_dir_label . update ( f"Selected directory: { self . _selected_dir } " )
46+ self ._update_selected_dir_label ( )
4547 if self ._directory_tree :
4648 self ._directory_tree .focus ()
4749
50+ def set_selected_dir (self , directory : str ) -> None :
51+ self ._selected_dir = directory
52+ self ._update_selected_dir_label ()
53+
54+ def _update_selected_dir_label (self ) -> None :
55+ self ._selected_dir_label .update (f"Selected directory: { self ._selected_dir } " )
56+
4857 async def on_directory_tree_directory_selected (
4958 self , event : DirectoryTree .DirectorySelected
5059 ) -> None :
5160 event .stop ()
5261 self ._selected_dir = str (event .path )
53- self ._selected_dir_label . update ( f"Selected directory: { self . _selected_dir } " )
62+ self ._update_selected_dir_label ( )
5463
5564 async def on_directory_tree_file_selected (
5665 self , event : DirectoryTree .FileSelected
@@ -59,10 +68,13 @@ async def on_directory_tree_file_selected(
5968 self .notify ("Only directories can be selected." , severity = "warning" )
6069
6170 async def on_button_pressed (self , event : Button .Pressed ) -> None :
62- if event .button .id != "confirm-button" :
71+ if event .button .id not in { "confirm-button" , "cancel-button" } :
6372 return
6473 event .stop ()
65- await self .action_confirm ()
74+ if event .button .id == "confirm-button" :
75+ await self .action_confirm ()
76+ else :
77+ self .action_cancel ()
6678
6779 async def action_confirm (self ) -> None :
6880 log .info ("path_edit - Confirm button pressed" )
0 commit comments