1- import asyncio
21from contextlib import suppress
32from os import getcwd , path
4- from typing import Awaitable , Callable , ClassVar , Iterable , Self , Sequence
3+ from typing import Callable , ClassVar , Iterable , Self , Sequence
54
6- from textual import events , on , work
5+ from textual import events , work
76from textual .binding import BindingType
87from textual .content import ContentText
98from textual .css .query import NoMatches
10- from textual .widgets .option_list import Option , OptionDoesNotExist
9+ from textual .widgets .option_list import OptionDoesNotExist
1110from textual .widgets .selection_list import Selection , SelectionType
1211
1312from rovr .classes .mixins import (
1716)
1817from rovr .classes .session_manager import SessionManager
1918from rovr .classes .textual_options import FileListSelectionWidget , LazySelection
20- from rovr .components import PopupOptionList
2119from rovr .functions import path as path_utils
2220from rovr .functions import pins as pin_utils
2321from rovr .functions import utils
3028)
3129from rovr .widgets import Button , Input , OptionList , SelectionList
3230
31+ from .file_list_right_click_menu import FileListRightClickMenu
32+
3333
3434class FileList (
3535 CheckboxRenderingMixin ,
@@ -914,12 +914,12 @@ async def action_open_right_click_menu(
914914 ) -> None :
915915 # Show right click menu
916916 try :
917- rightclickoptionlist : FileListRightClickOptionList = self .app .query_one (
918- FileListRightClickOptionList
917+ rightclickoptionlist : FileListRightClickMenu = self .app .query_one (
918+ FileListRightClickMenu
919919 )
920920 except NoMatches :
921921 # it happens, but I really cannot be bothered to figure it out
922- rightclickoptionlist = FileListRightClickOptionList (classes = "hidden" )
922+ rightclickoptionlist = FileListRightClickMenu (classes = "hidden" )
923923 await self .app .mount (rightclickoptionlist )
924924 rightclickoptionlist .remove_class ("hidden" )
925925 if event is None :
@@ -936,152 +936,3 @@ async def action_open_right_click_menu(
936936 )
937937 rightclickoptionlist .update_location (event )
938938 rightclickoptionlist .focus ()
939-
940-
941- class FileListRightClickOptionList (PopupOptionList ):
942- def __init__ (self , classes : str | None = None , id : str | None = None ) -> None :
943- # Only show unzip option for archive files
944- super ().__init__ (
945- id = id ,
946- classes = classes ,
947- )
948-
949- @on (events .Show )
950- def on_show (self ) -> None :
951- no_items : bool = (
952- self .app .file_list .highlighted_option
953- and self .app .file_list .highlighted_option .disabled
954- )
955- cannot_write : bool = self .app .file_list .options [0 ].id == "perm"
956- no_clip : bool = len (self .app .Clipboard .selected ) == 0
957-
958- options = []
959- longest_prompt = 0
960- for i , option in enumerate (config ["settings" ]["right_click" ]):
961- if "options" in option :
962- options .append (
963- Option (
964- f" { option ['icon' ]} { option ['group' ].capitalize ()} " ,
965- id = f"group{ i } " ,
966- disabled = no_items ,
967- )
968- )
969- else :
970- match option ["action" ]:
971- case "rovr:copy" :
972- options .append (
973- Option (
974- f" { option ['icon' ]} Copy " , "copy" , disabled = no_items
975- )
976- )
977- case "rovr:cut" :
978- options .append (
979- Option (f" { option ['icon' ]} Cut " , "cut" , disabled = no_items )
980- )
981- case "rovr:paste" :
982- options .append (
983- Option (
984- f" { option ['icon' ]} Paste " , "paste" , disabled = no_clip
985- )
986- )
987- case "rovr:new" :
988- options .append (
989- Option (
990- f" { option ['icon' ]} New Item " ,
991- "new" ,
992- disabled = cannot_write ,
993- )
994- )
995- case "rovr:rename" :
996- options .append (
997- Option (
998- f" { option ['icon' ]} Rename " ,
999- "rename" ,
1000- disabled = no_items ,
1001- )
1002- )
1003- case "rovr:delete" :
1004- options .append (
1005- Option (
1006- f" { option ['icon' ]} Delete " ,
1007- "delete" ,
1008- disabled = no_items ,
1009- )
1010- )
1011- case "rovr:zip" :
1012- options .append (
1013- Option (f" { option ['icon' ]} Zip " , "zip" , disabled = no_items )
1014- )
1015- case "rovr:unzip" :
1016- options .append (
1017- Option (
1018- f" { option ['icon' ]} Unzip " , "unzip" , disabled = no_items
1019- )
1020- )
1021- case "system:copy_highlighted" :
1022- options .append (
1023- Option (
1024- f" { option ['icon' ]} Copy Highlighted File Path " ,
1025- "copy_highlighted" ,
1026- disabled = no_items ,
1027- )
1028- )
1029- case "system:copy_current_directory" :
1030- options .append (
1031- Option (
1032- f" { option ['icon' ]} Copy Current Directory Path " ,
1033- "copy_current_directory" ,
1034- disabled = no_items ,
1035- )
1036- )
1037- case "system:copy_to_system_clip" :
1038- options .append (
1039- Option (
1040- f" { option ['icon' ]} Copy to System Clipboard " ,
1041- "copy_to_system_clip" ,
1042- disabled = no_items ,
1043- )
1044- )
1045- longest_prompt = max (longest_prompt , len (options [- 1 ].prompt ))
1046- for option in options :
1047- if option .id .startswith ("group" ):
1048- if len (option .prompt ) < longest_prompt - 2 :
1049- option ._set_prompt (f"{ option .prompt :<{longest_prompt - 2 }} " )
1050- else :
1051- option ._set_prompt (f"{ option .prompt } " )
1052- self .set_options (options )
1053- self .call_next (self .refresh )
1054-
1055- async def on_option_list_option_highlighted (
1056- self , event : OptionList .OptionHighlighted
1057- ) -> None :
1058- # Get the highlighted option
1059- if not event .option .id .startswith ("group" ):
1060- ...
1061-
1062- async def on_option_list_option_selected (
1063- self , event : OptionList .OptionSelected
1064- ) -> None :
1065- # Handle menu item selection
1066- if event .option .id .startswith ("group" ):
1067- # need to handle the submenu options here soon
1068- return
1069- elif event .option .id .startswith ("copy_" ) and hasattr (
1070- self .app .query_one ("CopyButton" ), f"{ event .option .id } "
1071- ):
1072- func : Callable [[], Awaitable | None ] = getattr (
1073- self .app .query_one ("CopyButton" ), f"action_{ event .option .id } "
1074- )
1075- if asyncio .iscoroutinefunction (func ):
1076- await func ()
1077- else :
1078- func ()
1079- elif hasattr (self .app .file_list , f"action_{ event .option .id } " ):
1080- func : Callable [[], Awaitable | None ] = getattr (
1081- self .app .file_list , f"action_{ event .option .id } "
1082- )
1083- if asyncio .iscoroutinefunction (func ):
1084- await func ()
1085- else :
1086- func ()
1087- self .go_hide ()
0 commit comments