Skip to content

Commit

Permalink
Improve macOS menu bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Jul 10, 2024
1 parent 43a04e7 commit b46faa9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cartridges/details_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ class DetailsDialog(Adw.Dialog):

cover_changed: bool = False

is_open = False

def __init__(self, game: Optional[Game] = None, **kwargs: Any):
super().__init__(**kwargs)

# Make it so only one dialog can be open at a time
self.__class__.is_open = True
self.connect("closed", lambda *_: self.set_is_open(False))

self.game: Game = game
self.game_cover: GameCover = GameCover({self.cover})

Expand Down Expand Up @@ -325,3 +332,6 @@ def choose_executable(self, *_args: Any) -> None:

def choose_cover(self, *_args: Any) -> None:
self.image_file_dialog.open(self.get_root(), None, self.set_cover)

def set_is_open(self, is_open: bool) -> None:
self.__class__.is_open = is_open
39 changes: 37 additions & 2 deletions cartridges/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,32 @@ class ApplicationDelegate(NSObject): # type: ignore
def applicationDidFinishLaunching_(self, *_args: Any) -> None:
main_menu = NSApp.mainMenu()

add_game_menu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
"Add Game", "add:", "n"
)

import_menu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
"Import", "import:", "i"
)

file_menu = NSMenu.alloc().init()
file_menu.addItem_(add_game_menu_item)
file_menu.addItem_(import_menu_item)

file_menu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
"File", None, ""
)
file_menu_item.setSubmenu_(file_menu)
main_menu.addItem_(file_menu_item)

show_hidden_menu_item = (
NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
"Show Hidden", "hidden:", "h"
)
)

windows_menu = NSMenu.alloc().init()

view_menu = NSMenu.alloc().init()
view_menu.addItem_(show_hidden_menu_item)

Expand Down Expand Up @@ -111,11 +131,23 @@ def applicationDidFinishLaunching_(self, *_args: Any) -> None:

NSApp.setHelpMenu_(help_menu)

def add_(self, *_args: Any) -> None:
if (not shared.win) or (not (app := shared.win.get_application())):
return

app.lookup_action("add_game").activate()

def import_(self, *_args: Any) -> None:
if (not shared.win) or (not (app := shared.win.get_application())):
return

app.lookup_action("import").activate()

def hidden_(self, *_args: Any) -> None:
if not shared.win:
return

shared.win.on_show_hidden_action()
shared.win.lookup_action("show_hidden").activate()

def shortcuts_(self, *_args: Any) -> None:
if (not shared.win) or (not (overlay := shared.win.get_help_overlay())):
Expand Down Expand Up @@ -360,7 +392,7 @@ def on_preferences_action(
_parameter: Any = None,
page_name: Optional[str] = None,
expander_row: Optional[str] = None,
) -> CartridgesWindow:
) -> Optional[CartridgesPreferences]:
if CartridgesPreferences.is_open:
return

Expand All @@ -383,6 +415,9 @@ def on_edit_game_action(self, *_args: Any) -> None:
DetailsDialog(shared.win.active_game).present(shared.win)

def on_add_game_action(self, *_args: Any) -> None:
if DetailsDialog.is_open:
return

DetailsDialog().present(shared.win)

def on_import_action(self, *_args: Any) -> None:
Expand Down

0 comments on commit b46faa9

Please sign in to comment.