Coverage for src/lexigram/admin/actions/row_manager/shortcuts.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 23:18 +0800

1""" 

2Keyboard shortcuts management for row actions. 

3 

4Handles keyboard shortcut registration and execution for row actions. 

5""" 

6 

7from __future__ import annotations 

8 

9from typing import Any 

10 

11from lexigram.admin.actions.row_manager.types import RowAction 

12from lexigram.admin.actions.shortcuts import KeyboardShortcutManager as _Base 

13 

14 

15class KeyboardShortcutManager(_Base[RowAction]): 

16 """Manages keyboard shortcuts for row actions.""" 

17 

18 def execute_shortcut( 

19 self, 

20 shortcut: str, 

21 record_id: Any, 

22 record: Any | None = None, 

23 ) -> RowAction | None: 

24 """Return the action for *shortcut* if it can execute for *record*.""" 

25 action = self._shortcuts.get(shortcut) 

26 if action and record and action.visible(record) and not action.disabled(record): 

27 return action 

28 return None 

29 

30 def get_registered_shortcuts_with_labels(self) -> dict[str, str]: 

31 """Return a mapping of shortcut → action label.""" 

32 return {sc: action.label for sc, action in self._shortcuts.items()}