Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/toad/client/application_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from agent_comms.nominal.declared_family import (
DeclaredFamily,
DeclaredOrder,
FamilyMeta,
declared_words,
)
Expand Down Expand Up @@ -148,7 +149,19 @@ def require_unwritten(cls, name: str, writers: tuple[type, ...]) -> None:
pass


class ApplicationAction(DeclaredAction[ClientApplication], affix="Action"):
class MenuPlace(DeclaredOrder):
"""Where a member sits in the menu and the palette; within a place, declaration order."""


class InMenu(MenuPlace):
"""The menu's body."""


class LastInMenu(MenuPlace):
"""After every other member, wherever it is declared."""


class ApplicationAction(DeclaredAction[ClientApplication], InMenu, affix="Action"):
"""Declared application shortcuts resolve before an editor takes the key."""

binding_prefix = "app."
Expand All @@ -160,9 +173,10 @@ def exclusive_claims[Binding](cls, bindings: tuple[Binding, ...]) -> tuple[Bindi

@classmethod
def menu(cls, app: ClientApplication) -> tuple[tuple[ApplicationAction, str], ...]:
"""Every offered member under its label, in declaration order."""
"""Every offered member under its label, by menu place, then in declaration order."""
return tuple((command, command.label(app))
for member in cls.members_with(cls) for command in member.offered(app))
for member in sorted(cls.members_with(cls), key=MenuPlace.position_of)
for command in member.offered(app))


# Declaration order is the order of the menu and the palette.
Expand Down Expand Up @@ -193,7 +207,7 @@ async def apply(self, app: ClientApplication) -> None:
app.session_navigation.direct_messages()


class QuitAction(ReplacesFrameworkAction, ApplicationAction):
class QuitAction(LastInMenu, ReplacesFrameworkAction, ApplicationAction):
"""Save preferences and quit the application."""

keys = {InputMode: ("ctrl+q",)}
Expand Down
Loading