Add dec to make methods no-op if no selection

This commit is contained in:
RumovZ 2021-04-25 08:35:21 +02:00
parent c71b684a94
commit 458d891d28
2 changed files with 14 additions and 0 deletions

View File

@ -65,6 +65,7 @@ browsing-nd-names = { $num }: { $name }
browsing-new = (new)
browsing-new-note-type = New note type:
browsing-no-flag = No Flag
browsing-no-selection = No cards or notes selected.
browsing-note = Note
# Exactly one character representing 'Notes'; should differ from browsing-card-initial.
browsing-note-initial = N

View File

@ -1009,6 +1009,19 @@ def ensure_editor_saved_on_trigger(func: Callable) -> Callable:
return pyqtSlot()(ensure_editor_saved(func)) # type: ignore
def skip_if_selection_is_empty(func: Callable) -> Callable:
"""Make the wrapped method a no-op and show a hint if the table selection is empty."""
@wraps(func)
def decorated(self: Any, *args: Any, **kwargs: Any) -> None:
if self.table.len_selection() > 0:
func(self, *args, **kwargs)
else:
tooltip(tr.browsing_no_selection())
return decorated
class KeyboardModifiersPressed:
"Util for type-safe checks of currently-pressed modifier keys."