From c15481a796013b9217534d0e40a63c305e23bc1d Mon Sep 17 00:00:00 2001 From: Sch Date: Sat, 22 Jul 2023 19:43:04 +0900 Subject: [PATCH] implement toggle abbreviations --- __main__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/__main__.py b/__main__.py index d9cc625..af5f0a5 100644 --- a/__main__.py +++ b/__main__.py @@ -17,6 +17,7 @@ def __init__(self): PROJECT_NAME, self.generate_menu() ) + self.enabled = True def add_abbreviation(self, pack_name: str, key: str, term: str, *, autogenerated: bool = False): if pack_name not in self.abbreviations: @@ -65,10 +66,21 @@ def remove_all_abbreviations(self): self.abbreviations.clear() self.amount = 0 + def toggle_enable(self): + if self.enabled: + self.remove_all_abbreviations() + else: + self.reload() + self.enabled = not self.enabled + + def is_enable_checked(self, _: MenuItem) -> bool: + return self.enabled + def generate_menu(self) -> Menu: return Menu( MenuItem(f'{self.amount} Abbreviations', lambda: None, enabled=False), Menu.SEPARATOR, + MenuItem('Enable Abbreviation', self.toggle_enable, checked=self.is_enable_checked), MenuItem('Open Setting Panel', lambda: start_setting_panel(self)), MenuItem('Reload', self.reload), MenuItem('Exit', self.terminate)