Skip to content

Commit

Permalink
implement toggle abbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
junhg0211 committed Jul 22, 2023
1 parent 5d1305e commit c15481a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c15481a

Please sign in to comment.